k8s snippets

Bash aliases / functions for kubectl

Tagged aliases, kubectl, k8s  Languages bash

Put the following functions in, for example, ~/.bash_aliases:

# Open a bash shell in the pod
function kshell() { kubectl exec -it "$1" -- /bin/bash ;}
# List pods
function kpods() { kubectl get po -n default -o wide ;}
function klogs() { kubectl logs -f "$1" ;}
function ktail() { kubectl logs --tail=100 -f "$1" ;}
# Restarts a pod
function krestart() { kubectl rollout restart "deployment/$1" ;}
# Stops a pod by scaling it to zero
function kstop() { kubectl scale --replicas=0 "deployment/$1" ;}
function kdesc() { kubectl describe pod $1 ;}
function ksecret() { kubectl get secret $1 -o jsonpath="{.data.$2}" | base64 --decode ;}
function ksecrets() { kubectl get secret/$1 -o yaml ;}

Your RSI symptoms and cognitive dissonance will disappear in about 6 months.

How to solve "CreateContainerConfigError" in Kubernetes

Tagged createcontainerconfigerror, k8s, kubectl  Languages bash

To solve CreateContainerConfigError try this command:

$ kubectl describe pod xxx-86cbd7555b-2zrs2
...
...
  Warning  Failed     75s (x8 over 2m50s)  kubelet, k8s-node1  Error: couldn't find key XXX in ConfigMap default/xxx
...