Lei Zhilong

The best way to input is to output

Jun 4, 2020 - 1 minute read - Comments - Cheat Sheets

Kubernetes

Disclaimer: This article will be updated from time to time to add new content or make any changes in exsisting sections without any notice. Using them under your own investigation in production is advised.

I. Kubernetes YAML tips

Here are 3 ways to create Kubernetes YAML templates without writing from scratch.

1. Using dryrun to generate YAML

1
2

kubectl create deployment nginx-deploy --image=nginx -o yaml --dry-run

2. Getting existing workload YAML

1
2

kubectl get deploy nginx-deploy -o yaml > nginx-deploy.yaml

3. Explaining spec by kubectl

1
2

kubectl explain pods.spec.containers

II. Command gists

1. Delete all Pods not Running

1
kubectl get po -A --no-headers | awk ‘/Terminating/{print $2 " -n " $1}' | xargs -L 1 kubectl delete --force po