Info

Small script and take a note to interact between kubectl and your kubernetes cluster.

You can explore command with kubectl in some place, including

Helpful command

Get base64 decode of secret with no more 3th party

kubectl get secrets -n <namespace> <secret> -o go-template='{{range $k,$v := .data}}{{"### "}}{{$k}}{{"\n"}}{{$v|base64decode}}{{"\n\n"}}{{end}}'

Debug your node via kubectl

kubectl debug node/my-node -it --image=<img>

Check the resource of workload with resource-capacity extension

Download via krew, find out the step at krew installing

# Extension: https://github.com/robscott/kube-capacity
 
# Check the available resources
kubectl resource-capacity -a
 
# Check detail resource utilize of all workload
kubectl resource-capacity -p --util

Scale down the statefulset application

# Use scale option
kubectl scale --replicas=0 sts <sts name>
 
# Or we can use patch or edit option
kubectl patch statefulsets <stateful-set-name> -p '{"spec":{"replicas":<new-replicas>}}'

You need to consider when apply scaling down can not working because β€œcannot scale down a StatefulSet when any of the stateful Pods it manages is unhealthy. Scaling down only takes place after those stateful Pods become running and ready.” . Read more in: Scale a StatefulSet

Delete pods with not on state Running

k delete pods -n <name-space> --field-selector=status.phase!=Running

Create the generic secrets from file, for example binary file with auto convert to base64 format

kubectlΒ create secret generic accounts-identityserver-certificate --from-file=certificate.pfxΒ --dry-run=client -oΒ yamlΒ >Β certificate_sec.yamlΒ 

Check currently config context

kubectl config view --minify

Change default storage class for your node

kubectl patch storageclass <sc-specific> -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'