Kubernetes

Kubernetes is an open-source container-orchestration system for automating computer application deployment, scaling, and management.

Use kubectl commands

The kubectl command line tool lets you control Kubernetes clusters. For configuration, kubectl looks for a file named config in the $HOME/.kube directory. You can specify other kubeconfig files by setting the KUBECONFIG environment variable or by setting the --kubeconfig flag.

Command overview: https://kubernetes.io/docs/reference/kubectl/overview/

List all running pods

kubectl get pods

# list pods in all namespaces
kubectl get pods -A

Delete pod

kubectl delete po demo-889bb54fc-4brqx

# force pod deletion
kubectl delete po demo-889bb54fc-4brqx --grace-period 0 --force 

Flush Kubernetes DNS

If you encounter DNS issues inside your K8s cluster it can sometimes help to restart the coredns service.

kubectl scale deployment.apps/coredns -n kube-system --replicas=0
kubectl scale deployment.apps/coredns -n kube-system --replicas=2

Get last 50 updated pods

Get all pods that are not in "Running" state

Get logs for pods

Delete pod in case it is stuck in "terminating"

Port Forwarding

Get all K8s worker nodes

Copy file from/to Pod

Copy file from/to pod to local machine.

Debug DNS inside a Kubernetes cluster

First install dnsutils

After that you can exec different commands from inside the dnsutils pod to test DNS resolution. In the example below the demo-reader is running as a headless service with 2 replica. Using nslookup we can verify that we get 2 IP addresses.

For more see https://kubernetes.io/docs/tasks/administer-cluster/dns-debugging-resolution/

Last updated