[Kubernetes] Kubernetes Create

1 minute read


Kubernetes Create

  • Kubernetes Create CLI
  • Diagram for kubectl create deployment

Kubernetes Create CLI

# As docker container cannot have two identical container names,
# k8s cannot have two identical resource with the same name in the same namespace
# cf. the previous resource_type == "pod", currently resource_tpye == "deployment", therefore can make it with the name "my-nginx" without deleting the pod
kubectl create deployment my-nginx --image nginx
# same as above
kubectl create deploy my-nginx --image nginx
kubectl create deployments my-nginx --image nginx

kubectl get pods

# can seet that 7cddc5685c is identical(meaning that the my-nginx pod was )
kubectl get all
# NAME                            READY   STATUS    RESTARTS   AGE
# pod/my-nginx-7cddc5685c-wqq9j   1/1     Running   0          38s
# 
# NAME                                  DESIRED   CURRENT   READY   AGE
# replicaset.apps/my-nginx-7cddc5685c   1         1         1  

kubectl delete deployment my-nginx

Diagram for kubectl create

img

  • 1) ask the api server for deployment == kubectl create deployment my-nginx --image nginx
  • 2) api server receives the command and store it in the etcd
  • 3) controller manager looks at all the different resource types, and when it sees a new resource type, a controller that’s in charge of the resource type(resource_type == “deployment”) creates a ReplicaSet
    • cf. the controller for resource type pod and deployment are built into every k8s
    • a deployment can’t create pods directly but create as ReplicaSet
    • so for each version that a deployement is made, a new ReplicaSet is created, meaning that the old version and the new version are running at the same time
  • 4) ReplicaSet controller, which is a part of the controller manager, would see the ReplicaSet definition and know that it needs to create some pods.
  • 5) the pods will be created by adding them to the database (by the ReplicaSet controller)
  • 6) The scheduler notices that the pods have not been scheduled to a node.
  • 🔗 Pod diagram’s 4~7 will follow