Kubernetes

From Cheatsheet
Jump to navigationJump to search


Links

Documentation:

Checks

# Show the Kubernetes and kubectl version.
kubectl version

# Get all deployed pods 
kubectl get deployments --all-namespaces

# Get all pods in all namespaces
kubectl get pods --all-namespaces

# List all pods in the current namespace, with more details
kubectl get pods -o wide

# Get pods of a specific type
kubectl get pods dnsutils

# Test DNS lookup within a pod
kubectl exec -i -t dnsutils -- nslookup google.com

# Test ping within a pod
kubectl exec -i -t dnsutils -- ping -c 4 google.com

# Show kube-flannel service logs within the Kubernetes environment
kubectl logs --namespace kube-system kube-flannel-ds-lc8c2 -c kube-flannel

# Detailed information about all flannel pods
kubectl get pods -n kube-system -l app=flannel -o wide

# Check a pods' config
kubectl get configmap -n kube-system coredns -o=jsonpath='{.data.Corefile}'

# Check existence of a pod within the kube-system namespace
kubectl get pod -n kube-system -l k8s-app=kube-dns

# List ReplicaSets within the kube-system namespace
kubectl -n kube-system  get rs

# List all pods with their associated labels within the kube-system namespace
kubectl -n kube-system get pods --show-labels

# Lookup detailed pod information within the kube-system namespace
kubectl -n kube-system describe pod calico-node-5jdrv

# List deployment information
kubectl -n kube-system get deployment/calico-kube-controllers -o yaml

Services

# Check existence of services existing in all namespaces
kubectl get svc --all-namespaces

# List all services in the namespace
kubectl get services

Basic commands

# Make a dnsutils pod based on an online yaml file
kubectl apply -f https://k8s.io/examples/admin/dns/dnsutils.yaml

# Make a dnsutils pod based on a local file
kubectl apply -f dnsutils-1.yaml

# Edit the configmap for the coredns utility
kubectl -n kube-system edit configmap coredns

# Delete all coredns pods within kube-system
kubectl get pod -n kube-system -l k8s-app=kube-dns --no-headers | awk '{print $1}' | xargs -I{} kubectl delete pod -n kube-system {}

# Edit coredns config
kubectl -n kube-system edit configmap coredns

Deleting

# Delete a named pod
kubetctl delete pod -n dnsutils

# Delete the coredns pod in the kube-systems namespace
kubectl delete pod coredns-56448757b9-jll52 -n kube-systems