Skip to content

Latest commit

 

History

History
97 lines (84 loc) · 2.75 KB

kubernetes-basic.md

File metadata and controls

97 lines (84 loc) · 2.75 KB

Basics

⬅️ Back to Kubernetes overview

Run simple pod

kubectl run nginx --image nginx --port 80

Get all pods in the current namespace

kubectl get pod

Get the specific pod

kubectl get pod nginx

See the logs of the pod and follow them

kubectl logs --follow nginx

See 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:80

Visit http://localhost:8888/ to view the default nginx page

Delete pod again

kubectl delete pod nginx

Inspect the cluster

kubectl get node

More cluster information

kubectl version
kubectl cluster-info
kubectl cluster-info dump | less

Exercise

Search 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.

Additional content: CLI - kubectl

  • How to even pronounce? kubecuddle (🥰) vs. kubecontrol vs. kubeCTL vs. ?
  • Types/groups of commands
  • 💡 imperative vs. declarative / create vs. apply - will revisit later
kubectl help

Also 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=kubectl

Even 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 k

To 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