- Set context in kube-system namespace
kubectl set-context context_name --namespace kube-system
kubectl get pods --show-labels
kubectl get po,svc,pv,pvc,deploy,rs
- Output resource without creationTimestamp, selfLink, uid, ResourceVersion, etc.
kubectl get deployment deployment_name -o yaml --export
- Create service by exposing port
kubectl expose rc nginx --port=80 --target-port=8000
kubectl expose pod pod_name --port=444 --name=frontend
kubectl create service clusterip service_name --tcp=5678:8080
- Set deployment's nginx container image to specific version and it's busybox container to busybox
kubectl set image deployment/nginx busybox=busybox nginx=nginx:1.9.1
- Update all deployments and replicasets using nginx to version 1.9.1
kubectl set image deployments,rc nginx=nginx:1.9.1 --all
- Update image of all containers of deamonset
kubectl set image deamonset ds_name *=nginx:1.9.1
kubectl run nginx --image=nginx
kubectl run nginx --image=nginx --restart=Never
kubectl run nginx --image=nginx --restart=OnFailure
kubectl run nginx --image=nginx --restart=OnFailure --schedule="* * * * *"
- Easily create pod resource yaml file
kubectl run nginx --image=nginx --restart=Never --port=80 --namespace=my_ns --command \
--serviceaccount=ma_sa --env=HOSTNAME=local --labels=unit=finance,env=dev \
--requests='cpu=100m,memory=256Mi' --limits='cpu=200m,memory=512Mi' \
--dry-run -o yaml -- /bin/sh -c 'echo hello'
- Easily create deployment resource
kubectl run deploy_name --replicas=2 --labels=run=load-balancer-example --image=busybox --port=8080
kubectl expose deyployment frontend --type=NodePort --name=frontend-service --port=6262 --target-port=8080
- Easily set service account for deployment
kubectl set serviceaccount deployment frontend user_name
- Easily create service resource
kubectl create service clusterip service_name --tcp=5678:8080 --dry-run -o yaml
kubectl rollout status
kubectl rollout history
kubectl rollout undo
kubectl explain --api-version="batch/v1beta1" cronjobs.spec