Kubernetes 学习整理(四)

Scale the app

Scaling will increase the number of Pods to the new desired state.

Pre-config: expose the app publicly

kubectl get services
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.43.0.1    <none>        443/TCP   6d
kubectl expose deployment/kubernetes-bootcamp --type="NodePort" --port 8080
service/kubernetes-bootcamp exposed
kubectl get services
NAME                  TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
kubernetes            ClusterIP   10.43.0.1       <none>        443/TCP          6d
kubernetes-bootcamp   NodePort    10.43.136.101   <none>        8080:32673/TCP   5s
kubectl get pods
NAME                                   READY   STATUS    RESTARTS   AGE
kubernetes-bootcamp-855d5cc575-v22dh   1/1     Running   0          2d
kubectl get pods --show-labels
NAME                                   READY   STATUS    RESTARTS   AGE   LABELS
kubernetes-bootcamp-855d5cc575-v22dh   1/1     Running   0          2d    app=kubernetes-bootcamp,pod-template-hash=855d5cc575,version=v1
kubectl get services --show-labels
NAME                  TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE   LABELS
kubernetes            ClusterIP   10.43.0.1       <none>        443/TCP          6d    component=apiserver,provider=kubernetes
kubernetes-bootcamp   NodePort    10.43.136.101   <none>        8080:32673/TCP   52s   app=kubernetes-bootcamp

一些概念

"App" 指的是您要在 Kubernetes 中运行的应用程序或服务。这可能包括一个或多个容器,定义了应用程序的代码和运行时环境。
"Deployment" 用于声明性地定义和管理 Pod 的副本, 指定应用程序的期望状态,包括副本数量、容器镜像和其他配置。
负责 Pod 的创建、更新和删除,以确保应用程序的指定副本数量在运行。实现滚动更新、回滚、扩展和缩减副本等操作。
"ReplicaSet" 负责确保在集群中始终运行指定数量的 Pod 副本。每个 Deployment 关联到一个或多个 ReplicaSet。
"Service" 用于定义一组 Pod 的网络端点,并提供负载均衡和服务发现。用于定义一个网络入口,将流量引导到一组 Pod。通常,一个 Service 与一个 Deployment 相关联,以提供对该 Deployment 管理的 Pod 的访问。

使用场景一: distribute traffic to all avalible pods.

当一个APP 运行在多个pod上时,需要一个方法将流量分发到各个pod上去。 Service 有集成的load-balancer可以实现网络分发的功能,它会使用endpoints来监控所有available pods.

Scaling a deployment

查看 deployment

kubectl get deployments
NAME                  READY   UP-TO-DATE   AVAILABLE   AGE
kubernetes-bootcamp   1/1     1            1           2d4h

NAME: lists the names of the Deployments in the cluster.
READY: 当前/预期 replicas。 shows the ratio of CURRENT/DESIRED replicas
UP-TO-DATE: 已达到预期的replicas数量。 displays the number of replicas that have been updated to achieve the desired state.
AVAILABLE: 能够给user使用的replica数量。 displays how many replicas of the application are available to your users.
AGE: APP running time. displays the amount of time that the application has been running.

查看replicaSet 数量

命名: deployment-name-randomstring

kubectl get rs
NAME                             DESIRED   CURRENT   READY   AGE
kubernetes-bootcamp-855d5cc575   1         1         1       2d5h

scale deployment 从 1 到 4

kubectl scale deployments/kubernetes-bootcamp --replicas=4
# deployment.apps/kubernetes-bootcamp scaled
kubectl get deployment
NAME                  READY   UP-TO-DATE   AVAILABLE   AGE
kubernetes-bootcamp   1/4     4            1           2d5h

确认scale之后的信息

kubectl get deployment
NAME                  READY   UP-TO-DATE   AVAILABLE   AGE
kubernetes-bootcamp   4/4     4            4           2d5h

kubectl get pods -o wide
NAME                                   READY   STATUS    RESTARTS   AGE    IP              NODE                   NOMINATED NODE   READINESS GATES
kubernetes-bootcamp-855d5cc575-kxrj6   1/1     Running   0          69s    10.42.236.127   ali1-atlantic-node-1   <none>           <none>
kubernetes-bootcamp-855d5cc575-v22dh   1/1     Running   0          2d5h   10.42.0.22      ali1-atlantic-node-3   <none>           <none>
kubernetes-bootcamp-855d5cc575-vqff8   1/1     Running   0          69s    10.42.65.179    ali1-atlantic-host     <none>           <none>
kubernetes-bootcamp-855d5cc575-x5ksr   1/1     Running   0          69s    10.42.208.227   ali1-atlantic-node-2   <none>           <none>

可以看到具体的event:Scaled up replica set kubernetes-bootcamp-855d5cc575 to 4 from 1


 kubectl describe deployments/kubernetes-bootcamp
Name:                   kubernetes-bootcamp
Namespace:              default
CreationTimestamp:      Sun, 21 Jan 2024 22:27:58 -0800
Labels:                 app=kubernetes-bootcamp
Annotations:            deployment.kubernetes.io/revision: 1
Selector:               app=kubernetes-bootcamp
Replicas:               4 desired | 4 updated | 4 total | 4 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=kubernetes-bootcamp
  Containers:
   kubernetes-bootcamp:
    Image:        gcr.io/google-samples/kubernetes-bootcamp:v1
    Port:         <none>
    Host Port:    <none>
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Progressing    True    NewReplicaSetAvailable
  Available      True    MinimumReplicasAvailable
OldReplicaSets:  <none>
NewReplicaSet:   kubernetes-bootcamp-855d5cc575 (4/4 replicas created)
Events:
  Type    Reason             Age    From                   Message
  ----    ------             ----   ----                   -------
  Normal  ScalingReplicaSet  2m14s  deployment-controller  Scaled up replica set kubernetes-bootcamp-855d5cc575 to 4 from 1

提取APP 相关port 和 随便哪个IP

但是外部是无法通过podip来访问的,~~得需要通过serviceIP, ~~
访问app, 要用它的node 和 port, 因为type是NodePort,意思是所有node上的这个port都可以访问


# 提取service的port
 export NODE_PORT="$(kubectl get services/kubernetes-bootcamp -o go-template='{{(index .spec.ports 0).nodePort}}')"
echo $NODE_PORT
# 32673


# 查看pod相关的IP,但是外部是无法通过podip来访问的,得需要通过serviceIP, 

kubectl get pods -l app=kubernetes-bootcamp -o wide
NAME                                   READY   STATUS    RESTARTS   AGE    IP              NODE                   NOMINATED NODE   READINESS GATES
kubernetes-bootcamp-855d5cc575-kxrj6   1/1     Running   0          10m    10.42.236.127   ali1-atlantic-node-1   <none>           <none>
kubernetes-bootcamp-855d5cc575-v22dh   1/1     Running   0          2d5h   10.42.0.22      ali1-atlantic-node-3   <none>           <none>
kubernetes-bootcamp-855d5cc575-vqff8   1/1     Running   0          10m    10.42.65.179    ali1-atlantic-host     <none>           <none>
kubernetes-bootcamp-855d5cc575-x5ksr   1/1     Running   0          10m    10.42.208.227   ali1-atlantic-node-2   <none>           <none>


# 查看service
kubectl get services -l app=kubernetes-bootcamp
NAME                  TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
kubernetes-bootcamp   NodePort   10.43.136.101   <none>        8080:32673/TCP   4h29m

# 查看service详情
kubectl describe services/kubernetes-bootcamp
Name:                     kubernetes-bootcamp
Namespace:                default
Labels:                   app=kubernetes-bootcamp
Annotations:              <none>
Selector:                 app=kubernetes-bootcamp
Type:                     NodePort
IP Family Policy:         SingleStack
IP Families:              IPv4
IP:                       10.43.136.101
IPs:                      10.43.136.101
Port:                     <unset>  8080/TCP
TargetPort:               8080/TCP
NodePort:                 <unset>  32673/TCP
Endpoints:                10.42.0.22:8080,10.42.208.227:8080,10.42.236.127:8080 + 1 more...
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

可以看到,每次访问都命中不同的pod, 也就是说做了load-balance.

export NODE_PORT="$(kubectl get services/kubernetes-bootcamp -o go-template='{{(index .spec.ports 0).nodePort}}')"
ali1-atlantic-host:~/k8scluster-automation # echo "NODE_PORT=$NODE_PORT"
NODE_PORT=32673
ali1-atlantic-host:~/k8scluster-automation #
ali1-atlantic-host:~/k8scluster-automation # export NODE_IP="$(kubectl get nodes -o jsonpath='{.items[0].status.addresses[?(@.type=="InternalIP")].address}')"
ali1-atlantic-host:~/k8scluster-automation # echo $NODE_IP
10.224.35.217

# 可以看到,每次访问都命中不同的pod, 也就是说做了load-balance.
ali1-atlantic-host:~/k8scluster-automation # curl http://"$NODE_IP:$NODE_PORT"
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-855d5cc575-kxrj6 | v=1
ali1-atlantic-host:~/k8scluster-automation # curl http://"$NODE_IP:NODE_PORT"
curl: (3) URL using bad/illegal format or missing URL
ali1-atlantic-host:~/k8scluster-automation # curl http://"$NODE_IP:$NODE_PORT"
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-855d5cc575-kxrj6 | v=1
ali1-atlantic-host:~/k8scluster-automation # curl http://"$NODE_IP:$NODE_PORT"
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-855d5cc575-vqff8 | v=1
ali1-atlantic-host:~/k8scluster-automation # curl http://"$NODE_IP:$NODE_PORT"
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-855d5cc575-x5ksr | v=1
ali1-atlantic-host:~/k8scluster-automation # curl http://"$NODE_IP:$NODE_PORT"
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-855d5cc575-x5ksr | v=1
ali1-atlantic-host:~/k8scluster-automation # curl http://"$NODE_IP:$NODE_PORT"
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-855d5cc575-x5ksr | v=1
ali1-atlantic-host:~/k8scluster-automation # curl http://"$NODE_IP:$NODE_PORT"
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-855d5cc575-kxrj6 | v=1

暂时无法解析hostname


curl http://"kubernetes-bootcamp:$NODE_PORT"
curl: (6) Could not resolve host: kubernetes-bootcamp

Scale Down 从4到2

# scale down from 4 to 2
kubectl scale deployments/kubernetes-bootcamp --replicas=2
#deployment.apps/kubernetes-bootcamp scaled

# check the deployment information
kubectl get deployments/kubernetes-bootcamp
NAME                  READY   UP-TO-DATE   AVAILABLE   AGE
kubernetes-bootcamp   2/2     2            2           2d6h

# check the service information 
kubectl get service  -l app=kubernetes-bootcamp
NAME                  TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
kubernetes-bootcamp   NodePort   10.43.136.101   <none>        8080:32673/TCP   5h30m

# show the detail information, 2 endpoints
kubectl describe services/kubernetes-bootcamp
Name:                     kubernetes-bootcamp
Namespace:                default
Labels:                   app=kubernetes-bootcamp
Annotations:              <none>
Selector:                 app=kubernetes-bootcamp
Type:                     NodePort
IP Family Policy:         SingleStack
IP Families:              IPv4
IP:                       10.43.136.101
IPs:                      10.43.136.101
Port:                     <unset>  8080/TCP
TargetPort:               8080/TCP
NodePort:                 <unset>  32673/TCP
Endpoints:                10.42.0.22:8080,10.42.236.127:8080
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>


kubectl get pods -o wide
NAME                                   READY   STATUS    RESTARTS   AGE    IP              NODE                   NOMINATED NODE   READINESS GATES
kubernetes-bootcamp-855d5cc575-kxrj6   1/1     Running   0          80m    10.42.236.127   ali1-atlantic-node-1   <none>           <none>
kubernetes-bootcamp-855d5cc575-v22dh   1/1     Running   0          2d6h   10.42.0.22      ali1-atlantic-node-3   <none>           <none>

使用场景二: rolling up without downtime.

用户希望APP 一直是available, 开发被要求一天要升级多个版本, rolling update能满足所有人的需求,保证升级过程中0停机。

A rolling update allows a Deployment update to take place with zero downtime.

查看当前service相关pod的详情

kubectl describe pods -l app=kubernetes-bootcamp

 
 kubectl describe pods -l app=kubernetes-bootcamp
Name:                 kubernetes-bootcamp-855d5cc575-kxrj6
Namespace:            default
Priority:             500000
Priority Class Name:  cmo-medium-priority
Service Account:      default
Node:                 ali1-atlantic-node-1/10.224.35.216
Start Time:           Wed, 24 Jan 2024 03:31:50 -0800
Labels:               app=kubernetes-bootcamp
                      pod-template-hash=855d5cc575
Annotations:          cni.projectcalico.org/containerID: 45bb5644d9dc7135a31392c35eaaec6dad831c3a47d0b131da86b1167e05b40c
                      cni.projectcalico.org/podIP: 10.42.236.127/32
                      cni.projectcalico.org/podIPs: 10.42.236.127/32
                      k8s.v1.cni.cncf.io/network-status:
                        [{
                            "name": "k8s-pod-network",
                            "ips": [
                                "10.42.236.127"
                            ],
                            "default": true,
                            "dns": {}
                        }]
Status:               Running
IP:                   10.42.236.127
IPs:
  IP:           10.42.236.127
Controlled By:  ReplicaSet/kubernetes-bootcamp-855d5cc575
Containers:
  kubernetes-bootcamp:
    Container ID:   containerd://9a4973511ec64365197a5693b42ebbdfcc453965055913d65114c9fc1714b10c
    Image:          gcr.io/google-samples/kubernetes-bootcamp:v1
    Image ID:       gcr.io/google-samples/kubernetes-bootcamp@sha256:0d6b8ee63bb57c5f5b6156f446b3bc3b3c143d233037f3a2f00e279c8fcc64af
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Wed, 24 Jan 2024 03:32:24 -0800
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-zkdff (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  kube-api-access-zkdff:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:                      <none>

将当前pod image升级到V2

注意到,升级后,除了Image 变为V2, event事件里也有详细message体现

kubectl set image deployments/kubernetes-bootcamp kubernetes-bootcamp=jocatalin/kubernetes-bootcamp:v2
deployment.apps/kubernetes-bootcamp image updated
ali1-atlantic-host:~/k8scluster-automation # kubectl describe pods -l app=kubernetes-bootcamp
Name:                 kubernetes-bootcamp-69b6f9fbb9-rvcz4
Namespace:            default
Priority:             500000
Priority Class Name:  cmo-medium-priority
Service Account:      default
Node:                 ali1-atlantic-node-3/10.224.35.209
Start Time:           Wed, 24 Jan 2024 04:58:39 -0800
Labels:               app=kubernetes-bootcamp
                      pod-template-hash=69b6f9fbb9
Annotations:          cni.projectcalico.org/containerID: 764a605c2c9b35abe4f78576fe5e902c5006d14c519aeda55e1dad5fc99dc637
                      cni.projectcalico.org/podIP: 10.42.0.23/32
                      cni.projectcalico.org/podIPs: 10.42.0.23/32
                      k8s.v1.cni.cncf.io/network-status:
                        [{
                            "name": "k8s-pod-network",
                            "ips": [
                                "10.42.0.23"
                            ],
                            "default": true,
                            "dns": {}
                        }]
Status:               Pending
IP:
IPs:                  <none>
Controlled By:        ReplicaSet/kubernetes-bootcamp-69b6f9fbb9
Containers:
  kubernetes-bootcamp:
    Container ID:
    Image:          jocatalin/kubernetes-bootcamp:v2
    Image ID:
    Port:           <none>
    Host Port:      <none>
    State:          Waiting
      Reason:       ContainerCreating
    Ready:          False
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-tzpnr (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  kube-api-access-tzpnr:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type    Reason          Age   From               Message
  ----    ------          ----  ----               -------
  Normal  Scheduled       2s    default-scheduler  Successfully assigned default/kubernetes-bootcamp-69b6f9fbb9-rvcz4 to ali1-atlantic-node-3
  Normal  AddedInterface  2s    multus             Add eth0 [10.42.0.23/32] from k8s-pod-network
  Normal  Pulling         1s    kubelet            Pulling image "jocatalin/kubernetes-bootcamp:v2"

查看pods状态

# 有一个pod 终止了
kubectl get pods
NAME                                   READY   STATUS        RESTARTS   AGE
kubernetes-bootcamp-69b6f9fbb9-nkncs   1/1     Running       0          98s
kubernetes-bootcamp-69b6f9fbb9-rvcz4   1/1     Running       0          2m24s
kubernetes-bootcamp-855d5cc575-kxrj6   1/1     Terminating   0          89m

# 活跃的pod变成2个了
kubectl get pods
NAME                                   READY   STATUS    RESTARTS   AGE
kubernetes-bootcamp-69b6f9fbb9-nkncs   1/1     Running   0          2m16s
kubernetes-bootcamp-69b6f9fbb9-rvcz4   1/1     Running   0          3m2s


# event事件
Events:
  Type     Reason          Age                    From               Message
  ----     ------          ----                   ----               -------
  Normal   Scheduled       3m36s                  default-scheduler  Successfully assigned default/kubernetes-bootcamp-69b6f9fbb9-nkncs to ali1-atlantic-host
  Normal   AddedInterface  3m36s                  multus             Add eth0 [10.42.65.180/32] from k8s-pod-network
  Warning  Failed          2m50s (x3 over 3m35s)  kubelet            Failed to pull image "jocatalin/kubernetes-bootcamp:v2": rpc error: code = Unknown desc = failed to pull and unpack image "docker.io/jocatalin/kubernetes-bootcamp:v2": failed to copy: httpReadSeeker: failed open: unexpected status code https://registry-1.docker.io/v2/jocatalin/kubernetes-bootcamp/manifests/sha256:fb1a3ced00cecfc1f83f18ab5cd14199e30adc1b49aa4244f5d65ad3f5feb2a5: 429 Too Many Requests - Server message: toomanyrequests: You have reached your pull rate limit. You may increase the limit by authenticating and upgrading: https://www.docker.com/increase-rate-limit
  Warning  Failed          2m50s (x3 over 3m35s)  kubelet            Error: ErrImagePull
  Normal   BackOff         2m13s (x5 over 3m35s)  kubelet            Back-off pulling image "jocatalin/kubernetes-bootcamp:v2"
  Warning  Failed          2m13s (x5 over 3m35s)  kubelet            Error: ImagePullBackOff
  Normal   Pulling         2m2s (x4 over 3m36s)   kubelet            Pulling image "jocatalin/kubernetes-bootcamp:v2"
  Normal   Pulled          2m1s                   kubelet            Successfully pulled image "jocatalin/kubernetes-bootcamp:v2" in 1.066946066s (1.066969801s including waiting)
  Normal   Created         2m1s                   kubelet            Created container kubernetes-bootcamp
  Normal   Started         2m                     kubelet            Started container kubernetes-bootcamp


Verify the update

kubectl describe services/kubernetes-bootcamp
Name:                     kubernetes-bootcamp
Namespace:                default
Labels:                   app=kubernetes-bootcamp
Annotations:              <none>
Selector:                 app=kubernetes-bootcamp
Type:                     NodePort
IP Family Policy:         SingleStack
IP Families:              IPv4
IP:                       10.43.136.101
IPs:                      10.43.136.101
Port:                     <unset>  8080/TCP
TargetPort:               8080/TCP
NodePort:                 <unset>  32673/TCP
Endpoints:                10.42.0.23:8080,10.42.65.180:8080
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

确认每次curl 都能访问到不同的pod,而且version == V2

export NODE_PORT="$(kubectl get services/kubernetes-bootcamp -o go-template='{{(index .spec.ports 0).nodePort}}')"
ali1-atlantic-host:~/k8scluster-automation #
ali1-atlantic-host:~/k8scluster-automation #
ali1-atlantic-host:~/k8scluster-automation # echo "NODE_PORT=$NODE_PORT"
NODE_PORT=32673
ali1-atlantic-host:~/k8scluster-automation #
ali1-atlantic-host:~/k8scluster-automation # echo $NODE_IP
10.224.35.217
ali1-atlantic-host:~/k8scluster-automation #
ali1-atlantic-host:~/k8scluster-automation # curl http://"$NODE_IP:$NODE_PORT"
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-69b6f9fbb9-rvcz4 | v=2
ali1-atlantic-host:~/k8scluster-automation # curl http://"$NODE_IP:$NODE_PORT"
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-69b6f9fbb9-nkncs | v=2
ali1-atlantic-host:~/k8scluster-automation # curl http://"$NODE_IP:$NODE_PORT"
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-69b6f9fbb9-rvcz4 | v=2

确认roll update state

kubectl rollout status deployments/kubernetes-bootcamp
deployment "kubernetes-bootcamp" successfully rolled out

Roll back an update

因为V10不存在,所以这条执行之后,会有个pod 处于error状态,无法pull image

kubectl set image deployments/kubernetes-bootcamp kubernetes-bootcamp=gcr.io/google-samples/kubernetes-bootcamp:v10
deployment.apps/kubernetes-bootcamp image updated
ali1-atlantic-host:~/k8scluster-automation # kubectl get deployments
NAME                  READY   UP-TO-DATE   AVAILABLE   AGE
kubernetes-bootcamp   2/2     1            2           2d6h
ali1-atlantic-host:~/k8scluster-automation #
ali1-atlantic-host:~/k8scluster-automation # kubectl get pods
NAME                                   READY   STATUS         RESTARTS   AGE
kubernetes-bootcamp-66566cb7f-b8qq5    0/1     ErrImagePull   0          13s
kubernetes-bootcamp-69b6f9fbb9-nkncs   1/1     Running        0          9m39s
kubernetes-bootcamp-69b6f9fbb9-rvcz4   1/1     Running        0          10m


kubectl logs kubernetes-bootcamp-66566cb7f-b8qq5
Error from server (BadRequest): container "kubernetes-bootcamp" in pod "kubernetes-bootcamp-66566cb7f-b8qq5" is waiting to start: trying and failing to pull image


查看deployment细节

kubectl describe deployment kubernetes-bootcamp
Name:                   kubernetes-bootcamp
Namespace:              default
CreationTimestamp:      Sun, 21 Jan 2024 22:27:58 -0800
Labels:                 app=kubernetes-bootcamp
Annotations:            deployment.kubernetes.io/revision: 3
Selector:               app=kubernetes-bootcamp
Replicas:               2 desired | 1 updated | 3 total | 2 available | 1 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=kubernetes-bootcamp
  Containers:
   kubernetes-bootcamp:
    Image:        gcr.io/google-samples/kubernetes-bootcamp:v10
    Port:         <none>
    Host Port:    <none>
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    False   ProgressDeadlineExceeded
OldReplicaSets:  kubernetes-bootcamp-855d5cc575 (0/0 replicas created), kubernetes-bootcamp-69b6f9fbb9 (2/2 replicas created)
NewReplicaSet:   kubernetes-bootcamp-66566cb7f (1/1 replicas created)
Events:
  Type    Reason             Age   From                   Message
  ----    ------             ----  ----                   -------
  Normal  ScalingReplicaSet  38m   deployment-controller  Scaled down replica set kubernetes-bootcamp-855d5cc575 to 2 from 4
  Normal  ScalingReplicaSet  26m   deployment-controller  Scaled up replica set kubernetes-bootcamp-69b6f9fbb9 to 1
  Normal  ScalingReplicaSet  25m   deployment-controller  Scaled down replica set kubernetes-bootcamp-855d5cc575 to 1 from 2
  Normal  ScalingReplicaSet  25m   deployment-controller  Scaled up replica set kubernetes-bootcamp-69b6f9fbb9 to 2 from 1
  Normal  ScalingReplicaSet  24m   deployment-controller  Scaled down replica set kubernetes-bootcamp-855d5cc575 to 0 from 1
  Normal  ScalingReplicaSet  16m   deployment-controller  Scaled up replica set kubernetes-bootcamp-66566cb7f to 1

rollback 回去

kubectl rollout undo deployments/kubernetes-bootcamp
deployment.apps/kubernetes-bootcamp rolled back
ali1-atlantic-host:~/k8scluster-automation #
ali1-atlantic-host:~/k8scluster-automation # kubectl get pods
NAME                                   READY   STATUS    RESTARTS   AGE
kubernetes-bootcamp-69b6f9fbb9-nkncs   1/1     Running   0          28m
kubernetes-bootcamp-69b6f9fbb9-rvcz4   1/1     Running   0          28m

clear env 删除deployment 和 service

kubectl get services
NAME                  TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
kubernetes            ClusterIP   10.43.0.1       <none>        443/TCP          6d6h
kubernetes-bootcamp   NodePort    10.43.136.101   <none>        8080:32673/TCP   6h9m
ali1-atlantic-host:~/k8scluster-automation # kubectl delete deployments/kubernetes-bootcamp services/kubernetes-bootcamp
deployment.apps "kubernetes-bootcamp" deleted
service "kubernetes-bootcamp" deleted
ali1-atlantic-host:~/k8scluster-automation # kubectl get services
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.43.0.1    <none>        443/TCP   6d6h

kubectl get deployments
No resources found in default namespace.
ali1-atlantic-host:~/k8scluster-automation # kubectl get pods
No resources found in default namespace.

posted @ 2024-01-24 21:45  vivi~  阅读(23)  评论(0编辑  收藏  举报