Docker Kubernetes YAML文件创建容器

通过创建Deployment来管理pods从而创建容器。它会同时创建容器、pod、以及Deployment !

环境:

  • 系统:Centos 7.4 x64
  • Docker版本:18.09.0
  • Kubernetes版本:v1.8
  • 管理节点:192.168.1.79
  • 工作节点:192.168.1.78
  • 工作节点:192.168.1.77

创建yaml文件

vim nginx-deployment.yaml
apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.9
        ports:
        - containerPort: 80
# 指定api版本
apiVersion: apps/v1beta2
# 指定需要创建的资源对象
kind: Deployment
# 源数据、可以写name,命名空间,对象标签
metadata:
# 指定创建对象名称
  name: nginx-deployment
# spec 描述pod相关信息
spec:
# pod 副本数,默认1
  replicas: 3
# pod 标签选择器
  selector:
# pod 匹配标签字段
    matchLabels:
# pod 匹配app值为nginx
      app: nginx
# 容器 描述pod具体信息
  template:
# 容器 指定标签
    metadata:
# 容器 匹配标签字段
      labels:
# 容器 匹配值aap值为nginx
        app: nginx
# 容器信描述信息
    spec:
# 指定容器信息
      containers:
# 指定容器名称
      - name: nginx
# 指定镜像名称
        image: nginx:1.10
# 暴露容器端口
        ports:
# 指定暴露容器端口
        - containerPort: 80
yaml参数注解

相关文章:

  • 2022-12-23
  • 2021-09-28
  • 2022-12-23
  • 2021-06-05
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-14
猜你喜欢
  • 2021-07-09
  • 2022-02-26
  • 2021-11-25
  • 2021-08-19
  • 2021-07-30
  • 2021-05-21
  • 2022-12-23
相关资源
相似解决方案