Docker Kubernetes  Service 代理服务创建

创建Service需要提前创建好pod容器。再创建Service时需要指定Pod标签,它会提供一个暴露端口默会分配容器内网访问的唯一IP地址。

环境:

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

一、通过deployment创建pod

1、创建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.12
        ports:
        - containerPort: 80
# 指定api版本
apiVersion: apps/v1beta2
# 指定需要创建的资源对象
kind: Deployment
# 源数据、可以写name,命名空间,对象标签
metadata:
# 指定对象名称
  name: nginx-deployment
# 描述资源相关信息
spec:
# 指定副本数
  replicas: 3
# 资源标签选择器
  selector:
# 匹配标签字段
    matchLabels:
# 标签名
      app: nginx
# 描述资源具体信息
  template:
# 源数据、可以写name,命名空间,对象标签
    metadata:
# 指定标签
      labels:
# 标签名
        app: nginx
# 描述资源相关信息
    spec:
# 容器管理
      containers:
# 容器名称
      - name: nginx
# 镜像名称
        image: nginx:1.12
# 端口管理
        ports:
# 指定暴露容器端口
        - containerPort: 80
文件注解

相关文章: