Kubernetes

“platform for automating deployment, scaling, and operations of application containers across clusters of hosts.”

References:

Best practice for health check

  • readiness probe: to know when to restart a Container
  • liveness probe: to know when a Container is ready to start accepting traffic

Debug Crashloopbackoff

Tools/Utilities

kubectl

Install

brew install kubectl 

Configuration

kubectl cluster-info # check the cluster info
kubectl config view # view config

Pod

kubectl get pod --all-namespaces
kubectl get pod -n default
kubectl get pod --all-namespaces --show-all -l "job-name=<job-name>" 

kubectl logs -f -n <namespace> <pod-name>
kubectl exec -it <pod-name> bash # it = interactive shell
kubectl port-forward <pod-name> 8080:8080

kubectl describe pod POD_NAME
kubectl got pod POD_NAME -o json

Deployment

kubectl get deploy --all-namespaces
kubectl get deploy -n <namespace> <deployment-name> -o yaml

Services

kubectl get svc --all-namespaces

Jobs

kubectl get job --all-namespaces

Copy

kubectl cp <file-spec-src> <file-spec-dest>
kubectl cp <file-spec-src> <file-spec-dest> -c <specific-container>

# Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace
kubectl cp /tmp/foo <some-namespace>/<some-pod>:/tmp/bar 

# Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace
kubectl cp <some-namespace>/<some-pod>:/tmp/foo /tmp/bar 

Check permission

kubectl auth can-i create deployments --namespace prod

Helm

The Package Manager for K8s

brew install kubernetes-helm

Cheatsheet

#  initialize the local CLI and also install Tiller 
helm init 

# update charts/ based on the contents of requirements.yaml
helm dependency update
helm dep update