⬅️ Back to Kubernetes overview
Run simple pod
kubectl run nginx --image nginx --port 80Get all pods in the current namespace
kubectl get podGet the specific pod
kubectl get pod nginxSee the logs of the pod and follow them
kubectl logs --follow nginxSee details of the pod like image, status, volumes, events etc.
kubectl describe pod nginx📝 What is the name of the node the pod is running on?
See the whole resource of the pod in YAML format
kubectl get pod nginx -o yaml📝 Does the pod have any label set? If yes, can you figure them out?
Expose the pod to be able to access it locally
kubectl port-forward pod/nginx 8888:80Visit http://localhost:8888/ to view the default nginx page
Delete pod again
kubectl delete pod nginxInspect the cluster
kubectl get nodeMore cluster information
kubectl version
kubectl cluster-info
kubectl cluster-info dump | lessSearch for the latest version of the Apache Httpd image on Docker Hub. Run it as a pod and display it in your browser.
When you are finished, please delete all created pods.
- How to even pronounce? kubecuddle (🥰) vs. kubecontrol vs. kubeCTL vs. ?
- Types/groups of commands
- 💡 imperative vs. declarative / create vs. apply - will revisit later
kubectl helpAlso see https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands and https://kubernetes.io/docs/reference/kubectl/conventions/
To save some typing, an alias on the kubectl command is very common
alias k=kubectlEven more convenience is provided with bash auto-completion
source <(kubectl completion bash)💡 This can auto-complete resource types, options and even specific resource names
But this does not work out of the box with the alias. But can be fixed
complete -F __start_kubectl kTo make these changes permanent, they can be put into the bash startup script
echo 'source <(kubectl completion bash)' >>~/.bashrc
echo 'alias k=kubectl' >>~/.bashrc
echo 'complete -F __start_kubectl k' >>~/.bashrc- 💡 zsh + https://github.com/ohmyzsh/ohmyzsh + kubectl plugin https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/kubectl is quite convenient and powerful
- 💡 IDEs provide integrations (listing resources, auto-completion, debugging) for Kubernetes which can be very helpful.