Skip to content

Latest commit

 

History

History
138 lines (94 loc) · 2.52 KB

kubectl.md

File metadata and controls

138 lines (94 loc) · 2.52 KB

kubectl example commands

  • Set context in kube-system namespace
kubectl set-context context_name --namespace kube-system
  • Get pods with labels
kubectl get pods --show-labels
  • Get all resources
kubectl get all
  • Get multiple resources
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
  • Create service for pod
kubectl expose pod pod_name --port=444 --name=frontend
  • Create ClusterIP service
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
  • Create nginx deployment
kubectl run nginx --image=nginx
  • Create nginx pod
kubectl run nginx --image=nginx --restart=Never
  • Create nginx job
kubectl run nginx --image=nginx --restart=OnFailure
  • Create nginx cronjob
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
  • Easily create service
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
  • Rollout
kubectl rollout status
kubectl rollout history
kubectl rollout undo
  • Browse documentation
kubectl explain --api-version="batch/v1beta1" cronjobs.spec