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. Deployment
s are connected byservice
(and abstraction of pods and deployments) where eachservice
can have few types mainlyClusterIP
,ExternalName
,LoadBalancer
andNodePort
.- The
service
types: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
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
findspods
throughselector
andservice
findpods
throughselector
.name
is also a similar idea,Ingress
findservice
by 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