Name | Command |
Run curl test temporarily | kubectl run --generator=run-pod/v1 --rm mytest --image=yauritux/busybox-curl -it |
Run wget test temporarily | kubectl run --generator=run-pod/v1 --rm mytest --image=busybox -it wget |
Run nginx deployment with 2 replicas | kubectl run my-nginx --image=nginx --replicas=2 --port=80 |
Run nginx pod and expose it | kubectl run my-nginx --restart=Never --image=nginx --port=80 --expose |
Run nginx deployment and expose it | kubectl run my-nginx --image=nginx --port=80 --expose |
List authenticated contexts | kubectl config get-contexts , ~/.kube/config |
Set namespace preference | kubectl config set-context <context_name> --namespace=<ns_name> |
List pods with nodes info | kubectl get pod -o wide |
List everything | kubectl get all --all-namespaces |
Get all services | kubectl get service --all-namespaces |
Get all deployments | kubectl get deployments --all-namespaces |
Show nodes with labels | kubectl get nodes --show-labels |
Get resources with json output | kubectl get pods --all-namespaces -o json |
Validate yaml file with dry run | kubectl create --dry-run --validate -f pod-dummy.yaml |
Start a temporary pod for testing | kubectl run --rm -i -t --image=alpine test-$RANDOM -- sh |
kubectl run shell command | kubectl exec -it mytest -- ls -l /etc/hosts |
Get system conf via configmap | kubectl -n kube-system get cm kubeadm-config -o yaml |
Get deployment yaml | kubectl -n denny-websites get deployment mysql -o yaml |
Explain resource | kubectl explain pods , kubectl explain svc |
Watch pods | kubectl get pods -n wordpress --watch |
Query healthcheck endpoint | curl -L http://127.0.0.1:10250/healthz |
Open a bash terminal in a pod | kubectl exec -it storage sh |
Check pod environment variables | kubectl exec redis-master-ft9ex env |
Enable kubectl shell autocompletion | echo "source <(kubectl completion bash)" >>~/.bashrc , and reload |
Use minikube dockerd in your laptop | eval $(minikube docker-env) , No need to push docker hub any more |
Kubectl apply a folder of yaml files | kubectl apply -R -f . |
Get services sorted by name | kubectl get services –sort-by=.metadata.name |
Get pods sorted by restart count | kubectl get pods –sort-by=’.status.containerStatuses[0].restartCount’ |
List pods and images | kubectl get pods -o=’custom-columns=PODS:.metadata.name,Images:.spec.containers[*].image’ |
List all container images | list-all-images.sh |
kubeconfig skip tls verification | skip-tls-verify.md |
Ubuntu install kubectl | =”deb https://apt.kubernetes.io/ kubernetes-xenial main”= |
Reference | GitHub: kubernetes releases |
Reference | minikube cheatsheet, docker cheatsheet, OpenShift CheatSheet |
请发表评论