kubectl version
kubectl api-resources
kubectl api-versions
kubectl cluster-info
kubectl get nodes
kubectl get nodes master -o wide
kubectl describe nodes master
kubectl config view
kubectl config current-context
kubectl config use-context kubernetes-admin@kubernetes
kubectl config get-clusters
kubectl config get-contexts
kubectl get namespaces
kubectl get namespaces -o yaml
kubectl describe namespace default
kubectl create namespace my-namespace
kubectl delete namespace my-namespace
kubectl get pods
kubectl get pods --all-namespaces
kubectl get pods -namespace=my-namespace
kubectl run my-pod-1 --image=nginx:latest --dry-run
kubectl run my-pod-1 --image=nginx:latest --dry-run=client
kubectl run my-pod-2 --image=nginx:latest --namespace=my-namespace
kubectl run nginx --image=nginx -l --labels=app=test
kubectl get pods --show-labels
kubectl get pods -o wide
kubectl get pods --sort-by=.metadata.name
kubectl logs my-pod-1
kubectl get pods my-pod-2 --namespace=my-namespace -o wide
kubectl logs my-pod-2 --namespace=my-namespace
kubectl describe pod my-pod-1
kubectl describe pods my-pod-1 --namespace=my-namespace
kubectl delete pod my-pod-1
kubectl delete pods my-pod-1 --namespace=my-namespace
kubectl get deployments
kubectl get deployments --namespace=my-namespace
kubectl create deployment my-deployment-1 --image=nginx
kubectl get deployment my-deployment-1
kubectl get deployment my-deployment-1 --show-labels
kubectl describe deployments my-deployment-1
kubectl get deployment my-deployment-1 -o yaml
kubectl set image deployment my-deployment-1 nginx=nginx:1.16.1
kubectl rollout history deployment my-deployment-1
kubectl rollout undo deployment my-deployment-1
kubectl rollout undo deployment my-deployment-1 --to-revision=2
kubectl rollout status deployment my-deployment-1
kubectl rollout restart deployment my-deployment-1
kubectl scale --replicas=3 deployment my-deployment-1
kubectl scale --current-replicas=3 --replicas=5 deployment my-deployment-1 This will create an HPA (Horizontal Pod Aotuscaler)
kubectl autoscale deployment my-deployment-1 --min=2 --max=10
First, create a pod with the label app=myapp.
Then:
kubectl run my-pod --image=nginx --labels=app=myapp
Create a service of type NodePort which will use pod's labels for selector but we have to specify the type, so create a definition file first and then create a service
kubectl expose pod my-pod --port=80 --name nginx-service --type=NodePort --dry-run=client -o yaml
kubectl create service nodeport nginx --tcp=80:80 --node-port=30080 --dry-run=client -o yaml
kubectl get service
kubectl get service -o wide
kubectl get service --show-labels
kubectl get services --all-namespaces
kubectl describe service nginx-service
kubectl get service nginx-service
kubectl delete service nginx-service
First, create a definition file for a pod
kubectl run mypod --image=nginx --dry-run=client -o yaml > my-pod.yml
kubectl create -f my-pod.yml
kubectl delete -f my-pod.yml