Docker 创建管理 Service

Docker 创建管理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

管理节点:创建service文件

vim nginx-service.yaml

apiVersion: v1
kind: Service
metadata:
  name: nginx-service
  labels:
    app: nginx
spec:
  ports:
  - port: 8888
    targetPort: 80
  selector:
    app: nginx
# 指定api版本
apiVersion: v1
# 指定需要创建资源对象
kind: Service
# 源数据、可以写name,命名空间,对象标签
metadata:
# 服务名称
  name: nginx-service
# 标签
  labels:
# service绑定pod标签
    app: nginx
# deployment标签
spec:
  ports:
# 暴露端口
  - port: 88
# 容器端口
    targetPort: 80
# pod标签名称
  selector:
    app: nginx
yaml文件注解

管理节点:创建serivce

kubectl create -f nginx-service.yaml

猜你喜欢

转载自www.cnblogs.com/xiangsikai/p/10011548.html
今日推荐