Kubernetes Survival Guide
In this doc:
- Basic how to commands
- Basic fixes / troubleshooting
- Deploy and expose apps
- Create my own app and add to kubernetes
- Stateful apps and storage locations
- Deployments as configs
- Architecture and terms
- How the network fits together
Separate Docs:
- Cluster from scratch ( kubeadm )
- Different pre built solutions: Minikube, MicroK8s, EKS, Rancher, kops, kubespray, k3s)
- Kops and Kubespray
Basic how to commands
kubectl get namespace
kubectl config set-context --current --namespace=kube-system
kubectl version
kubectl cluster-info
kubectl cluster-info dump
kubectl config view
kubectl get nodes
kubectl describe nodes # ton of info about nodes
kubectl get deployments
kubectl describe deployment
kubectl get pod
kubectl get pods
kubectl get pods –output=wide # more info, including IPs
kubectl get pod -A # all name space
kubectl get pods --namespace=kube-system # specify name space
kubectl describe pods
kubectl describe pod my_pod1
kubectl get events
kubectl get svc
kubectl get services
kubectl describe services/nginx
kubectl get pod,svc -n kube-system # view pod,svc for kube-system
kubectl delete service hello-node
kubectl delete deployment hello-node
kubectl logs my_pod1
kubectl exec my_pod1 -- env # run command on pod
kubectl exec -ti my_pod1 -- bash # get shell on pod
kubectl exec -ti my_pod1 -- /bin/sh # get shell on pod
kubectl top pods # show pod CPU / Mem
kubectl top pods -A # all name spaces
kubectl top pod my_pod1 # specific pod
Deployments and Services
kubectl create deployment nginx --image=nginx
kubectl expose deployment nginx --type=NodePort --port=8080
kubectl expose deployment nginx2 --type=LoadBalancer --port=8080
kubectl delete service nginx
kubectl proxy # default 8001 on local host
curl http://localhost:8001/version # or wherever proxy is located
curl http://localhost:8001/api/v1/namespaces/default/pods # info about pods
curl 192.168.3.223:8001/api/v1/namespaces/default/pods/nginx-676b6c5bbc # info about a pod
kubectl label pods nginx-676b6c5bbc version=v1 # label a pod
kubectl get pods -l version=v1 # get pods with a label
kubectl get services -l version=v1 # get services with a label
kubectl delete service -l app=nginx
kubectl get rs # show replica sets
kubectl scale nginx --replicas=4 # scale up
kubectl scale nginx --replicas=2 # scale down
kubectl set image myapp myapp:v2 # update image for deployment
kubectl rollout status myapp # check status of rollout
kubectl rollout undo myapp # roll back if failed
Basic fixes / troubleshooting
Deploy and Expose Apps
Stateful apps and storage locations
nginx ( multiple instances with IDs, update pages, access pages with LB ) mysql postgres awx prometheus/grafana
Helm:
sudo snap install helm --classic
Create my own app and add to kubernetes
Deployments as configs
Architecture and terms
How the network fits together
Service types:
- ClusterIP (default)
- setup internal IP within cluster - for apps within the cluster
- cluster network / pod network
- also load balances
- NodePort
- specified port setup on each node in cluster ( each node becomes an LB ?? )
- also creates ClusterIP ( automatic )
- Access with: NodeIP:NodePort
- OK if you can access nodes directly
- expose with NAT
- also load balances
- 30000 - 32767
- LoadBalancer
- create load balancer with external IP (NEEDS third party LB!!!!)
- cloud only ????? how to setup manually??????
- also creates NodePort and Cluster IP
- ExternalName - setup a DNS name
- ??????
Communication:
- container-to-container ( localhost )
- Pod-to-Pod - pod network ( cluster network ), connected accross nodes, Container Networking Interface (CNI), CNI Plugins - Calico, Flannel, more
- Pod-to-Service - service proxy - monitors EndpointSlices and routes traffic
- External-to-Service - Gateway API (or its predecessor, Ingress) makes services available outside the cluster
Differnt address ranges:
- pods - IPs assigned by network plugin
- services - IPs assigned by Kube-api server
-
nodes - IPs assigned by kublet or cloud-controller-manager
- all pods can connect to all other pods
- agents on a node (ex kubelet) can connect to all pods on that node
Show cluster IP ( pod ) and external IP:
kubectl get services
Show cluster IPs ( pod ) and endpoint IPs ( service ):
kubectl describe service nginx