Listing all resources in a namespace

Based on this comment , the supported way to list all resources is to iterate through all the api versions listed by kubectl api-resources: kubectl api-resources enumerates the resource types available in your cluster. this means you can combine it with kubectl get to actually list every instance of every resource type in a namespace: … Read more

Restart container within pod

Is it possible to restart a single container Not through kubectl, although depending on the setup of your cluster you can “cheat” and docker kill the-sha-goes-here, which will cause kubelet to restart the “failed” container (assuming, of course, the restart policy for the Pod says that is what it should do) how do I restart … Read more

how to pass environment variable in kubectl deployment?

I used envsubst (https://www.gnu.org/software/gettext/manual/html_node/envsubst-Invocation.html) for this. Create a deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: $NAME labels: app: nginx spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: – name: nginx image: nginx:1.7.9 ports: – containerPort: 80 Then: export NAME=my-test-nginx envsubst < deployment.yaml | kubectl apply -f – Not sure … Read more

kubectl unable to connect to server: x509: certificate signed by unknown authority

One more solution in case it helps anyone: My scenario: using Windows 10 Kubernetes installed via Docker Desktop ui 2.1.0.1 the installer created config file at ~/.kube/config the value in ~/.kube/config for server is https://kubernetes.docker.internal:6443 using proxy Issue: kubectl commands to this endpoint were going through the proxy, I figured it out after running kubectl … Read more

How to create a kubectl config file for serviceaccount

# your server name goes here server=https://localhost:8443 # the name of the secret containing the service account token goes here name=default-token-sg96k ca=$(kubectl get secret/$name -o jsonpath=”{.data.ca\.crt}”) token=$(kubectl get secret/$name -o jsonpath=”{.data.token}” | base64 –decode) namespace=$(kubectl get secret/$name -o jsonpath=”{.data.namespace}” | base64 –decode) echo ” apiVersion: v1 kind: Config clusters: – name: default-cluster cluster: certificate-authority-data: ${ca} … Read more

kubectl apply vs kubectl create?

Those are two different approaches: Imperative Management kubectl create is what we call Imperative Management. On this approach you tell the Kubernetes API what you want to create, replace or delete, not how you want your K8s cluster world to look like. Declarative Management kubectl apply is part of the Declarative Management approach, where changes … Read more

‘kubectl patch’ works on Linux Bash but not in Windows Powershell ISE

For detailed and very useful background, see the answer by mklement0 After much frustration, I have decided to list all variants of quote escaping that I’ve tried, and came up with one more, which suddenly worked! So, sharing it here: kubectl patch deployment wapi-backend-d1 –patch ‘{\”spec\”: {\”template\”: {\”metadata\”: {\”labels\”: {\”date\”: \”test123\”}}}}}’ This is how to … Read more