Kubernetes Deployment

本文详细介绍了Kubernetes Deployment的概念,包括无状态应用、手动和自动伸缩Pod、版本管理和各种部署策略。还讨论了Deployment的状态管理和使用技巧,强调了无状态应用的重要性以及如何选择合适的部署策略。
摘要由CSDN通过智能技术生成
什么是Deployment?

Deployment提供了运行Pod能力,并且为Pod提供滚动升级、伸缩、副本等功能,一般用于运行无状态的应用。目前建议使用Deployment来代替RelicaSet及ReplicationController的使用。

什么是无状态应用?

无状态应用是不将数据或应用程序状态存储到容器中,这将使无状态应用程序更具可伸缩性。例如前端应用是无状态的,可以部署多个副本以提高其可用性并在需求低时进行缩减,并且这些副本不需要唯一的标识。

Deployment操作

创建Deployment
kubectl create deployment nginx-deployment --image=nginx:1.16
通过yaml文件操作
kubectl apply -f nginx-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.16

在这里插入图片描述
查看Deployment列表
kubectl get deployment
在这里插入图片描述
查看Deployment描述信息
kubectl describe deployment
在这里插入图片描述

Deployment 手动伸缩Pod数量

方式1. 通过kubectl set image
kubectl scale deployment nginx-deployment --replicas 5
在这里插入图片描述
方式2. 通过YAML资源定义清单
kubectl apply -f nginx-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 5
  selector:
    matchLabels:
      app: nginx
  template
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值