美文网首页Kubernetes
Kubernetes | Deployment的创建过程

Kubernetes | Deployment的创建过程

作者: 奶茶不要奶不要茶 | 来源:发表于2022-06-11 21:23 被阅读0次
Deployment的创建过程(侵删)
搞清楚Pod的创建过程后,又去学习了下Deployment,如上图Deployment涉及到了 controller-manager 组件,这次也实践测试一波。
# apiserver controller-manager scheduler 都是运行中的
[root@k8s-master-01 ~]# ss -lnpt
State      Recv-Q Send-Q                              Local Address:Port                                             Peer Address:Port
LISTEN     0      128                                     127.0.0.1:10248                                                       *:*                   users:(("kubelet",pid=21656,fd=23))
LISTEN     0      128                                     127.0.0.1:9099                                                        *:*                   users:(("calico-node",pid=28589,fd=8))
LISTEN     0      128                                     127.0.0.1:37967                                                       *:*                   users:(("containerd",pid=951,fd=15))
LISTEN     0      128                                     127.0.0.1:10259                                                       *:*                   users:(("kube-scheduler",pid=18682,fd=7))
LISTEN     0      8                                               *:179                                                         *:*                   users:(("bird",pid=28684,fd=7))
LISTEN     0      128                                             *:22                                                          *:*                   users:(("sshd",pid=945,fd=3))
LISTEN     0      128                                          [::]:10249                                                    [::]:*                   users:(("kube-proxy",pid=29819,fd=13))
LISTEN     0      128                                          [::]:10250                                                    [::]:*                   users:(("kubelet",pid=21656,fd=15))
LISTEN     0      128                                          [::]:6443                                                     [::]:*                   users:(("kube-apiserver",pid=3268,fd=7))
LISTEN     0      128                                          [::]:10256                                                    [::]:*                   users:(("kube-proxy",pid=29819,fd=12))
LISTEN     0      128                                          [::]:10257                                                    [::]:*                   users:(("kube-controller",pid=25655,fd=7))
LISTEN     0      128                                          [::]:22                                                       [::]:*                   users:(("sshd",pid=945,fd=4))
[root@k8s-master-01 ~]# kubectl get pods
No resources found in default namespace.
[root@k8s-master-01 ~]# kubectl get deploy
No resources found in default namespace.
[root@k8s-master-01 ~]# cat nginx-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80
[root@k8s-master-01 ~]# kubectl apply -f nginx-deployment.yaml
deployment.apps/nginx-deployment created
[root@k8s-master-01 ~]#
[root@k8s-master-01 ~]# kubectl get deploy
NAME               READY   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   3/3     3            3           98s
[root@k8s-master-01 ~]# kubectl describe deploy nginx-deployment
Name:                   nginx-deployment
Namespace:              default
CreationTimestamp:      Sat, 11 Jun 2022 21:03:19 +0800
Labels:                 app=nginx
Annotations:            deployment.kubernetes.io/revision: 1
Selector:               app=nginx
Replicas:               3 desired | 3 updated | 3 total | 3 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=nginx
  Containers:
   nginx:
    Image:        nginx:latest
    Port:         80/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    NewReplicaSetAvailable
OldReplicaSets:  <none>
NewReplicaSet:   nginx-deployment-8d545c96d (3/3 replicas created)
Events:
  Type    Reason             Age   From                   Message
  ----    ------             ----  ----                   -------
  Normal  ScalingReplicaSet  110s  deployment-controller  Scaled up replica set nginx-deployment-8d545c96d to 3
[root@k8s-master-01 ~]#
[root@k8s-master-01 ~]# kubectl get pods
NAME                               READY   STATUS    RESTARTS   AGE
nginx-deployment-8d545c96d-586g7   1/1     Running   0          2m18s
nginx-deployment-8d545c96d-9vqwb   1/1     Running   0          2m18s
nginx-deployment-8d545c96d-bq46r   1/1     Running   0          2m18s
[root@k8s-master-01 ~]#
[root@k8s-master-01 ~]# kubectl get pods -owide
NAME                               READY   STATUS    RESTARTS   AGE     IP               NODE            NOMINATED NODE   READINESS GATES
nginx-deployment-8d545c96d-586g7   1/1     Running   0          4m31s   172.30.107.67    k8s-master-01   <none>           <none>
nginx-deployment-8d545c96d-9vqwb   1/1     Running   0          4m31s   172.20.183.131   k8s-master-03   <none>           <none>
nginx-deployment-8d545c96d-bq46r   1/1     Running   0          4m31s   172.21.176.204   k8s-master-02   <none>           <none>
[root@k8s-master-01 ~]# curl http://172.30.107.67
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
[root@k8s-master-01 ~]# curl http://172.20.183.131
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
[root@k8s-master-01 ~]# curl http://172.21.176.204
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
[root@k8s-master-01 ~]#

查看Depoyment的 Events 事件,是由deployment-controller 处理的,Pod也全部创建成功。
Pod内的服务也能访问,没啥问题。

controller-manager 停掉试试。

[root@k8s-master-01 ~]# kubectl delete -f nginx-deployment.yaml
deployment.apps "nginx-deployment" deleted
[root@k8s-master-01 ~]# kubectl get pods
No resources found in default namespace.
[root@k8s-master-01 ~]# systemctl stop kube-controller-manager
[root@k8s-master-01 ~]# ss -lnpt
State      Recv-Q Send-Q                              Local Address:Port                                             Peer Address:Port
LISTEN     0      128                                     127.0.0.1:10248                                                       *:*                   users:(("kubelet",pid=21656,fd=23))
LISTEN     0      128                                     127.0.0.1:9099                                                        *:*                   users:(("calico-node",pid=28589,fd=8))
LISTEN     0      128                                     127.0.0.1:37967                                                       *:*                   users:(("containerd",pid=951,fd=15))
LISTEN     0      128                                     127.0.0.1:10259                                                       *:*                   users:(("kube-scheduler",pid=18682,fd=7))
LISTEN     0      8                                               *:179                                                         *:*                   users:(("bird",pid=28684,fd=7))
LISTEN     0      128                                             *:22                                                          *:*                   users:(("sshd",pid=945,fd=3))
LISTEN     0      128                                          [::]:10249                                                    [::]:*                   users:(("kube-proxy",pid=29819,fd=13))
LISTEN     0      128                                          [::]:10250                                                    [::]:*                   users:(("kubelet",pid=21656,fd=15))
LISTEN     0      128                                          [::]:6443                                                     [::]:*                   users:(("kube-apiserver",pid=3268,fd=7))
LISTEN     0      128                                          [::]:10256                                                    [::]:*                   users:(("kube-proxy",pid=29819,fd=12))
LISTEN     0      128                                          [::]:22                                                       [::]:*                   users:(("sshd",pid=945,fd=4))
[root@k8s-master-01 ~]#
[root@k8s-master-01 ~]# kubectl apply -f nginx-deployment.yaml
deployment.apps/nginx-deployment created
[root@k8s-master-01 ~]# kubectl get deploy
NAME               READY   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   0/3     0            0           8s
[root@k8s-master-01 ~]# kubectl get pods
No resources found in default namespace.
[root@k8s-master-01 ~]# kubectl describe deploy nginx-deployment
Name:                   nginx-deployment
Namespace:              default
CreationTimestamp:      Sat, 11 Jun 2022 21:11:56 +0800
Labels:                 app=nginx
Annotations:            <none>
Selector:               app=nginx
Replicas:               3 desired | 0 updated | 0 total | 0 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=nginx
  Containers:
   nginx:
    Image:        nginx:latest
    Port:         80/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Events:           <none>
[root@k8s-master-01 ~]#
[root@k8s-master-01 ~]# kubectl get pods
No resources found in default namespace.
[root@k8s-master-01 ~]# kubectl get deploy
NAME               READY   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   0/3     0            0           2m13s
[root@k8s-master-01 ~]#
[root@k8s-master-01 ~]# systemctl start kube-controller-manager
[root@k8s-master-01 ~]# kubectl get deploy
NAME               READY   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   0/3     0            0           3m22s
[root@k8s-master-01 ~]# kubectl get deploy
NAME               READY   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   3/3     3            3           3m34s
[root@k8s-master-01 ~]#
[root@k8s-master-01 ~]# kubectl get pods
NAME                               READY   STATUS    RESTARTS   AGE
nginx-deployment-8d545c96d-sp9q6   1/1     Running   0          86s
nginx-deployment-8d545c96d-t686q   1/1     Running   0          86s
nginx-deployment-8d545c96d-tnv9g   1/1     Running   0          86s
[root@k8s-master-01 ~]#

controller-manager 停掉后,Deployment就异常了,没法正常创建Pod。组件重新启动就又正常了。
这也说明Deployment确实依赖 controller-manager 组件。
搞清楚这些关系对问题排查有很大帮助,嗯嗯嗯,又学习到了哈~~~

相关文章

网友评论

    本文标题:Kubernetes | Deployment的创建过程

    本文链接:https://www.haomeiwen.com/subject/ubewmrtx.html