kubernetes,

Kubernetes Cheat Sheet

Eugene Low Eugene Low Follow Mar 23, 2022 · 2 mins read
Share this

Kubernetes Cheat Sheet

Kubernetes Hierarchy and Knowledge Check.

Deployment > ReplicaSet > Pods > Container

  • Usually deployment decides how a pods would behave and where to get the container.
  • Deployments are connected by service(and abstraction of pods and deployments) where each service can have few types mainly ClusterIP, ExternalName, LoadBalancer and NodePort.
  • The service types:
    • ClusterIP(default): open network in cluster (node cannot access)
    • ExternalName: acts like CNAME of DNS and alias
    • LoadBalancer: open network to cloud provider/external load balancer.
    • NodePort: open to every node.
  • The service are able to route requests within the cluster from the port of the service to the target port of the deployment and pods.
  • selector is a very important key in the config files, its used to identify the kubernetes components where it is related, ie, deployment finds pods through selector and service find pods through selector. name is also a similar idea, Ingress find service by the name.

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
Written by Eugene Low
Hi, I am Eugene!