# Kubernetes Cheat Sheet * minikube ip #### kubectl commands [pods] * ```kubectl describe pod <podname>``` * ```kubectl exec -it <podname> sh ```// or any other command ### inside services, targetPort defaults to port * ### NodePort :::success helps with defining custom port numbers for exposing a service to other services or even outside world. When we select type: NodePort in the spec, it enables an option in ports field namely, nodePort. Range for this nodePort lies in 30000-32672 (approx) ::: * ### LoadBalancer :::success ::: * ### ClusterIP :::success means can only be accessed inside the cluster and not outside of the cluster micro-service takes advantage of cluster ip for internal communication. Very good case is database services. ## ReplicaSets part of apps group api version v1 contains a template for the pod definitions selector tag is required ## Deployments * part of apps group * api version v1 * deployments are entities that manage your replica sets basically deployments will create replica sets for you and they provide ways to roll updates based on workload or other parameters deployments are tagged with a deployment id * when we decide to roll a new update, older updates replicas will be reduced to zero after the update is successful * however the replica set is not removed as if we want to roll back to the older version, in case something goes wrong with the newer deployment * do not roll updates carelessly as each time it'll create another replica set and even tho it'll be empty with no replicas (pods) in it, it'll lead to a lot of clutter in your environment, which you probably want to avoid ## RollOuts * ``` sudo kubectl rollout history deployment ``` * ``` sudo kubectl rollout undo deployment <deployment-name> --to-revision=<number> ``` :::danger ###### NOTE: By default it'll roll back to one revision, --to-revision=<number> helps with specific roll out versions ## ROLLBACLS SHOULD ONLY BE USED IN EXTREME CONDITIONS SINCE IT'LL NOT UPDATE THE DEPLOYMENT FILES ##### IMMEDIATE ACTION AFTER THE ROLLBACK SHOULD BE TO UPDATE THE YAML FILES ::: :::success deployment name ```replicaset.apps/backend-934875bh``` pod name will follow a structure as ```backend-934875bh-jkb345``` ::: #### TIPS: * make use of release tags in pod definitions, helps with releasing the apps based on different versions