欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

K8S Deployment的应用

程序员文章站 2022-07-14 09:24:45
...

示例配置文件:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80

查询部署状态:

[[email protected] k8s]# kubectl describe deployments.apps 
Name:                   nginx
Namespace:              default
CreationTimestamp:      Tue, 21 Jan 2020 16:29:41 +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:1.7.9
    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-54f57cf6bf (3/3 replicas created)
Events:
  Type    Reason             Age   From                   Message
  ----    ------             ----  ----                   -------
  Normal  ScalingReplicaSet  14m   deployment-controller  Scaled up replica set nginx-54f57cf6bf to 3

查看pod状态:

[[email protected] k8s]# kubectl get pod
NAME                     READY   STATUS    RESTARTS   AGE
nginx-54f57cf6bf-2t2qd   1/1     Running   0          16m
nginx-54f57cf6bf-smwfh   1/1     Running   0          16m
nginx-54f57cf6bf-wztl4   1/1     Running   0          16m

查看部署位置:

[[email protected] k8s]# kubectl get pod -o wide
NAME                     READY   STATUS    RESTARTS   AGE   IP             NODE     NOMINATED NODE   READINESS GATES
nginx-54f57cf6bf-2t2qd   1/1     Running   0          16m   192.168.1.23   node-2   <none>           <none>
nginx-54f57cf6bf-smwfh   1/1     Running   0          16m   192.168.1.21   node-2   <none>           <none>
nginx-54f57cf6bf-wztl4   1/1     Running   0          16m   192.168.1.22   node-2   <none>           <none>
相关标签: K8S kubernetes