Skip to content

Kubernetes

  1. Open ~/.kube.config

  2. Modify contexts section:

    contexts:
    - context:
    cluster: cluster1
    user: cluster1
    name: dev
    - context:
    cluster: cluster2
    namespace: namespace1
    user: cluster2
    name: namespace1
    - context:
    cluster: cluster3
    namespace: db
    user: cluster3
    name: prod
    current-context: prod
Terminal window
kubectl config use-context <context>
Terminal window
kubectl get ns

This will also update the relevant context’s namespace value in the ~/.kube/config file.

Terminal window
kubectl config set-context --current --namespace=<namespace>
Terminal window
kubectl get all
Terminal window
kubectl logs pod/<pod>

Use ‘helm upgrade’ to install new version of a chart

Section titled “Use ‘helm upgrade’ to install new version of a chart”

This is far simpler than a more complex helm install command with tons of --set options.

Terminal window
helm upgrade <release name> <chart name> --reuse-values

More information here.

The normal access would be something like this:

Terminal window
kubectl get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d

But doing the same thing for a secret with a dot in its name wouldn’t work, thus:

Terminal window
kubectl get secret docker-config -o jsonpath="{.data.\.dockerconfigjson}" | base64 -d

An alternative would be to use go-template:

Terminal window
kubectl get secret docker-config -o 'go-template={{index .data ".dockerconfigjson"}}' | base64 -d
Terminal window
kubectl auth can-i --list
Terminal window
kubectl get nodes \
-o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{range .status.images[*]}{"\t"}{.names[0]}{"\n"}{end}{end}' | \
awk -F '@' '{print $1}' | \
awk '{$1=$1;print}' | \
sort -u
  1. List nodes: kubectl get nodes

  2. Deploy debugging pod to node: kubectl debug node/mynode -it --image=ubuntu

  3. Refresh packages and install curl: apt update && apt install curl -y

  4. Install crictl:

    Terminal window
    VER="v1.31.1"
    curl -sL https://github.com/kubernetes-sigs/cri-tools/releases/download/${VER}/crictl-${VER}-linux-amd64.tar.gz | \
    tar xzf - -C /usr/local/bin && \
    export \
    CONTAINER_RUNTIME_ENDPOINT=unix:///host/run/containerd/containerd.sock \
    IMAGE_SERVICE_ENDPOINT=unix:///host/run/containerd/containerd.sock

More information here and here.

Terminal window
kubectl annotate es my-secret force-sync=$(date +%s) --overwrite

More information here.

List all pod images by namespace and pod name

Section titled “List all pod images by namespace and pod name”
Terminal window
kubectl get pods -o jsonpath='{range .items[*]}{@.metadata.namespace}{" "}{@.metadata.name}{" "}{@..containers..image}{" "}{"\n"}{end}' | column -t

The output will have the name of the active namespace (or from all namespace if instead of -o the -Ao option is used), pod name, and the image names from all the containers in the pod. The ‘column’ command is used to nicely format the output as a table.