more tips
linkedin.com/in/omerberatsezer github.com/omerbsezer
kubectl get
list resources
(pods, services, nodes, deployments)
user@k8s:$ kubectl get pods # list all pods
user@k8s:$ kubectl get services # list all services
user@k8s:$ kubectl get deployments # list all deployments
user@k8s:$ kubectl get nodes # list all nodes
user@k8s:$ kubectl get pods -o wide -A # all pods in all namespaces
linkedin.com/in/omerberatsezer
kubectl describe
show detailed information
about a specific resource
user@k8s:$ kubectl describe pod <pod-name>
# details of a specific pod in default namespace
user@k8s:$ kubectl describe service <service-name>
# details of a specific service in default namespace
user@k8s:$ kubectl describe pod <pod-name> -n <namespace>
# details of a specific pod in specific namespace
linkedin.com/in/omerberatsezer
kubectl apply
create or update resources
using a YAML file
user@k8s:$ kubectl apply -f <file.yaml>
# apply changes from a YAML file
linkedin.com/in/omerberatsezer
kubectl delete
remove resources
from the cluster
user@k8s:$ kubectl delete pod <pod-name>
# delete a specific pod
user@k8s:$ kubectl delete -f <file.yaml>
# delete resources defined in a YAML file
linkedin.com/in/omerberatsezer
kubectl logs
view logs from
a specific pod or container
user@k8s:$ kubectl logs <pod-name>
# logs from a single-container pod
user@k8s:$ kubectl logs <pod-name> -c <container-name>
# logs from a specific container in a pod
linkedin.com/in/omerberatsezer
kubectl exec
execute a command
inside a running pod
user@k8s:$ kubectl exec -it <pod-name> -- /bin/bash
# start a bash shell in a pod
user@k8s:$ kubectl exec <pod-name> -- ls /app
# run `ls /app` inside the pod
linkedin.com/in/omerberatsezer
kubectl scale
adjust the number of
replicas for a deployment
user@k8s:$ kubectl scale deployment <deployment-name> --replicas=3
# scale to 3 replicas
linkedin.com/in/omerberatsezer
kubectl expose
create a service to expose
a pod or deployment
user@k8s:$ kubectl expose deployment <deployment-name> --
type=NodePort --port=8080
# expose a deployment on port 8080
linkedin.com/in/omerberatsezer
kubectl port-forward
forward local ports to a pod
for testing or debugging
user@k8s:$ kubectl port-forward <pod-name> 8080:80
# forward local port 8080 to pod's port 80
linkedin.com/in/omerberatsezer
kubectl roll-out
manage and monitor
deployment rollouts
(status, undo)
user@k8s:$ kubectl rollout status deployment/<deployment-name>
# check the status of a rollout
user@k8s:$ kubectl rollout undo deployment/<deployment-name>
# rollback to the previous version
linkedin.com/in/omerberatsezer
kubectl config
manage kubeconfig file
(for multiple cluster switching)
user@k8s:$ kubectl config get-contexts
# list available contexts.
user@k8s:$ kubectl config use-context <context-name>
# switch to a specific context.
user@k8s:$ kubectl config view
# view current configuration details.
linkedin.com/in/omerberatsezer