08- Kubernetes-Deployment入门

Posted 爱学习de测试小白

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了08- Kubernetes-Deployment入门相关的知识,希望对你有一定的参考价值。

Deployment入门


前言

  • 本篇来学习Deployment相关基础知识

Deployment

  • 在kubernetes中,Pod是最小的控制单元,但是kubernetes很少直接控制Pod,一般都是通过Pod控制器来完成的。Pod控制器用于pod的管理,确保pod资源符合预期的状态,当pod的资源出现故障时,会尝试进行重启或重建pod

命令方式

  • 命令格式: kubectl run deployment名称 [参数]
  • –image 指定pod的镜像
  • –port 指定端口
  • –replicas 指定创建pod数量
  • –namespace 指定namespace
# 创建
[root@master ~]# kubectl run nginx --image=nginx:latest --port=80 --replicas=3 -n test
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
deployment.apps/nginx created

# 查看创建的pod
[root@master ~]# kubectl get pod -n test
NAME                    READY   STATUS    RESTARTS   AGE
nginx-dd6b5d745-86529   1/1     Running   0          18s
nginx-dd6b5d745-qhzvs   1/1     Running   0          18s
nginx-dd6b5d745-rbnx2   1/1     Running   0          18s

# 查看deployment的信息   UP-TO-DATE:成功升级的副本数量   AVAILABLE:可用副本的数量
[root@master ~]# kubectl get deploy -n test
NAME    READY   UP-TO-DATE   AVAILABLE   AGE
nginx   3/3     3  

# 查看deployment的详细信息
[root@master ~]# kubectl describe deploy nginx -n test
Name:                   nginx
Namespace:              test
CreationTimestamp:      Mon, 04 Apr 2022 10:05:30 +0800
Labels:                 run=nginx
Annotations:            deployment.kubernetes.io/revision: 1
Selector:               run=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:  run=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-dd6b5d745 (3/3 replicas created)
Events:
  Type    Reason             Age    From                   Message
  ----    ------             ----   ----                   -------
  Normal  ScalingReplicaSet  2m50s  deployment-controller  Scaled up replica set nginx-dd6b5d745 to 3

# 删除deployment
[root@master ~]# kubectl delete deploy nginx -n test
deployment.apps "nginx" deleted

配置方式

  • 创建一个deploy-nginx.yaml,内容如下:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  namespace: dev
spec:
  replicas: 3
  selector:
    matchLabels:
      run: nginx
  template:
    metadata:
      labels:
        run: nginx
    spec:
      containers:
      - image: nginx:latest
        name: nginx
        ports:
        - containerPort: 80
          protocol: TCP
  • 创建命令:kubectl create -f deploy-nginx.yaml

  • 删除命令:kubectl delete -f deploy-nginx.yaml

以上是关于08- Kubernetes-Deployment入门的主要内容,如果未能解决你的问题,请参考以下文章

MySQL安装及配置 -- 2019-08-08 20:38:08

熊猫日期时间切片:junkdf.ix['2015-08-03':'2015-08-06'] 不起作用

芯片解密MC9S08DZ16 飞思卡尔系列芯片解密

Linux系统引导过程 -- 2019-08-08 20:40:08

基于hive的拉链表设计实现

《安富莱嵌入式周报》第224期:2021.08.02--2021.08.08