- # 指定使用的 Kubernetes API 版本
- apiVersion: apps/v1
- # 指定资源类型,这里是 Deployment
- kind: Deployment
- # 设置 Deployment 的元数据
- metadata:
- # 设置 Deployment 的名称为 "nginx-deployment"
- name: nginx-deployment
- # 为 Deployment 设置标签,这些标签将被用于选择器(selector)
- labels:
- app: nginx
- # 设置 Deployment 的规格
- spec:
- # 设置副本数量为 3,这意味着将创建 3 个 Nginx pod
- replicas: 3
- # 设置选择器,用于匹配模板(template)中的标签
- selector:
- # 匹配模板中具有 "app: nginx" 标签的 pod
- matchLabels:
- app: nginx
- # 设置 pod 模板
- template:
- # 设置 pod 的元数据
- metadata:
- # 为 pod 设置标签,这些标签将被用于选择器(selector)
- labels:
- app: nginx
- # 设置 pod 的规格
- spec:
- # 定义容器列表
- containers:
- # 定义名为 "nginx" 的容器
- - name: nginx
- # 使用 "nginx:1.19.10" 镜像启动容器
- image: nginx:1.19.10
- # 暴露容器的 80 端口
- ports:
- - containerPort: 80
复制代码
|