useful commands¶
kubectl: get pod¶
get information about all running pods
kubectl get pod
kubectl: describe pod¶
Get more information about one pod.
kubectl describe pod PODNAME
kubectl: expose pod¶
expose the port of a pod (creates a new service)
kubectl expose pod PODNAME --port=PORT_NUMBER --name=FRONTEND
kubectl: port-forward¶
port forward the exposed pod port on your local machine
kubectl port-forward PODNAME PORT_NUMBER
kubectl: attach¶
attach to a pod
kubectl attach PODNAME -i
kubectl: exec¶
Execute a command
kubectl exec PODNAME -- COMMAND
kubectl: label pods¶
Add a enw label to a pod
kubectl label pods PODNAME mylabel=LABEL
kubectl: run¶
Run a shell in a pod. This should run sh inside a busybox container.
kubectl run -i --tty busybox --image=busybox --restart=Never -- sh
kubectl: get deployments¶
show information on current deployments
kubectl get deployments
kubectl: get rs¶
get information on replica sets
kubectl get rs
kubectl: show pod labels¶
get pods and show the labels
kubectl get pods --show-labels
kubectl: rollout status¶
get deployment status
kubectl rollout status deployment/DEPLOYMENT_NAME
kubectl: set image¶
Run a deployment with a new image label. Can be used to run multiple versions.
kubectl set image deployment/DEPLOYMENT_NAME k8s-demo=k8s-demo:2
kubectl: edit¶
edit the deployment object
kubectl edit dpeloyment/DEPLOYMENT_NAME
kubectl: rollout status¶
get the status of a rollout
kubectl rollout status deployment/DEPLOYMENT_NAME
kubectl: rollout history¶
get the rollout history
kubectl rollout history deployment/DEPLOYMENT_NAME
kubectl: rollout undo¶
rollback to a previous version
kubectl rollout undo deployment/DEPLOYMENT_NAME
To rollback to a specific version use:
kubectl rollout undo deployment/DEPLOYMENT_NAME --to-revision=n
get a certificate from a tls secret¶
kubectl -n cert-manager get secret wafflelab-ca-secret -o jsonpath=’{.data.ca.crt}’ | base64 -d