kubectl useful commands - timowang1991/kubernetes-docs GitHub Wiki

kubectl apply/delete

How to start pods

kubectl apply -f k8s/
kubectl get pods
kubectl get deployments

How to stop pods

kubectl delete -f k8s



k8s persistent volume

kubectl get pv  # persistent volume
kubectl get pvc



kubectl exec

kubectl get pods
kubectl exec -it ipengine-net-benchmark-488656591-gjrpc /bin/bash
  • specify container
kubectl exec -it ipengine-net-benchmark-488656591-gjrpc -c ipengine-net-benchmark-iperf-server /bin/bash



kubectl port-forward

  • If you have permission to your pod which is running a server on port 8000, run the following
kubectl get pods
kubectl port-forward ipengine-net-benchmark-488656591-gjrpc 8000:8000



kubectl logs

kubectl logs ipengine-net-benchmark-488656591-gjrpc
  • if you have multiple containers in a pod, use -c to specify
kubectl logs ipengine-net-benchmark-488656591-gjrpc -c ipengine-net-benchmark



kubectl context

kubectl config get-contexts

CURRENT   NAME                 CLUSTER            AUTHINFO           NAMESPACE
*         docker-desktop       docker-desktop     docker-desktop
kubectl config use-context docker-desktop



kubectl namespace

kubectl get namespace
kubectl create namespace my-namespace
kubectl delete namespace my-namespace
kubectl config set-context --current --namespace=my-namespace
kubectl get pods -n my-namespace
kubectl exec -n my-namespace -it ipengine-net-benchmark-488656591-gjrpc -- sh



kubectl wait

kubectl wait --for=condition=complete --timeout=30s job/myjob



kubectl rollout status

kubectl rollout status deployment/some-deployment
⚠️ **GitHub.com Fallback** ⚠️