Docker Kubernetes  hostPort 代理转发

hostPort:

  • 1. 类似docker -p 映射宿主级端口到容器。
  • 2. 容器所在的主机暴露端口转发到指定容器中。
  • 3. hostport是通过代理转发的。

环境:

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

1、创建yaml文件

vim hostport.yaml

apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod2
  labels:
    app: nginx
spec:
  containers:
  - name: nginx
    image: nginx:1.10
    ports:
    - name: http
      containerPort: 80
      hostIP: 0.0.0.0
      hostPort: 89
      protocol: TCP
    - name: https
      containerPort: 443
      hostIP: 0.0.0.0
      hostPort: 443
      protocol: TCP
# 指定api版本
apiVersion: v1
# 指定需要创建的资源对象
kind: Pod
metadata:
# 源数据、可以写name,命名空间,对象标签
  name: nginx-pod2
# 指定标签
  labels:
# 标签名
    app: nginx
# 描述资源相关信息
spec:
# 指定容器信息
  containers:
# 容器名
  - name: nginx
# 容器镜像名
    image: nginx:1.10
# hostport管理
    ports:
# 指定http端口名称
    - name: http
# 指定容器端口
      containerPort: 80
# hsotip监听IP,可通过哪些宿主级ip访问
      hostIP: 0.0.0.0
# 宿主级暴露端口,它会映射到containerport的容器端口
      hostPort: 89
# 指定协议类型
      protocol: TCP
# 指定https
    - name: https
# 指定容器端口
      containerPort: 443
# hsotip监听IP,可通过哪些宿主级ip访问
      hostIP: 0.0.0.0
# 宿主级暴露端口,它会映射到containerport的容器端口
      hostPort: 443
# 指定协议类型
      protocol: TCP
文件注解

相关文章:

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