Kubernetes Cheat Sheet
Kubernetes Hierarchy and Knowledge Check.
Deployment > ReplicaSet > Pods > Container
- Usually
deploymentdecides how a pods would behave and where to get the container. Deployments are connected byservice(and abstraction of pods and deployments) where eachservicecan have few types mainlyClusterIP,ExternalName,LoadBalancerandNodePort.- The
servicetypes:ClusterIP(default): open network in cluster (node cannot access)ExternalName: acts like CNAME of DNS and aliasLoadBalancer: open network to cloud provider/external load balancer.NodePort: open to every node.
- The
serviceare able to route requests within the cluster from the port of the service to the target port of the deployment and pods. selectoris a very important key in the config files, its used to identify the kubernetes components where it is related, ie,deploymentfindspodsthroughselectorandservicefindpodsthroughselector.nameis also a similar idea,Ingressfindserviceby thename.
Get all
kubectl get all -A;
Log
kubectl logs component/componentName -n namespace;
# OR
kubectl logs component componentName -n namespace;
Set Current/Active Namespace
kubectl config set-context --current --namespace=namespace;
Rolling update/restart
rollout instead of rolling
kubectl rollout restart deployment/deployment_name;
# to revert
kubectl rollout undo deployment/deployment_name;
# to list/check history
kubectl rollout history deployment/deployment_name;
# to describe history of a revision X
kubectl rollout history deployment/deployment_name --revision X;
Trigger a cronjob
kubectl create job --from=cronjob/<name of cronjob> <name of job> -n namespace;
* I highly suggest learning the basics of the Kubernetes from this Youtube by Kubernetes Tutorial for Beginners [FULL COURSE in 4 Hours] by TechWorld with Nana although it is lengthy and read kubernetes components configuration from the reference instead of the website where kubernetes provided, they are lengthy and confusing.
[Youtube by Kubernetes Tutorial for Beginners [FULL COURSE in 4 Hours] by TechWorld with Nana]: https://www.youtube.com/watch?v=X48VuDVv0do
Eugene Low