自建kubernetes ingress-nginx 和ingress-istio 暴露服务端口

文档说明:自建K8S,只记录关键地方;
只介绍 ingress-nginx 和 ingress-istio (Traefik 与之述类似)

  1. ingress-nginx
  2. ingress-istio

关键点

  type: NodePort  # 关键点: 类型是nodePort   只需要修改这里就可以了
  externalIPs:    # 关键点: 需要暴露服务端口的工作节点 只需要修改这里就可以了
    - 192.168.3.121
    - 192.168.3.122
    - 192.168.3.123

ingress service 组件--ingress-nginx

方法一,修改配置文件

apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
    app.kubernetes.io/version: 1.4.0
  name: ingress-nginx-controller
  namespace: ingress-nginx
spec:
  ipFamilies:
  - IPv4
  ipFamilyPolicy: SingleStack
  ports:
  - appProtocol: http
    name: http
    port: 80
    protocol: TCP
    targetPort: http
  - appProtocol: https
    name: https
    port: 443
    protocol: TCP
    targetPort: https
  selector:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
  type: NodePort  # 关键点: 类型是nodePort  只需要修改这里就可以了
  externalIPs:    # 关键点: 需要暴露的工作节点  只需要修改这里就可以了
    - 192.168.3.121
    - 192.168.3.122
    - 192.168.3.123

方法二: 命令行里 kubectl edit 编辑配置文件

kubectl edit service/ingress-nginx-controller -n ingress-nginx

  type: NodePort
  externalIPs:
    - 192.168.3.121
    - 192.168.3.122

ingress service 组件--istio

# 创建一个新的配置文件

apiVersion: v1
kind: Service
metadata:
  annotations: null
  labels:
    app: istio-ingressgateway
    istio: ingressgateway
    release: istio
  name: istio-ingressgateway-my-custom
  namespace: istio-system
spec:
  ports:
    - name: http2
      port: 80
      targetPort: 8080
    - name: https
      port: 443
      targetPort: 8443
  selector:
    app: istio-ingressgateway
    istio: ingressgateway
  type: NodePort  # 关键点: 类型是nodePort  只需要修改这里就可以了
  externalIPs:    # 关键点: 需要暴露的工作节点  只需要修改这里就可以了
    - 192.168.3.121
    - 192.168.3.122


方法二: 命令行里 kubectl edit 编辑配置文件

# 修改 istio 服务配置,暴露端口 (可以修改默认的配置,也可以自建一个服务配置)
kubectl edit service/istio-ingressgateway -n istio-system

  type: NodePort
  externalIPs:
    - 192.168.3.121
    - 192.168.3.122

参考文档

  1. ingress-controllers
  2. ingress service
  3. ingress-nginx部署
  4. ingress-nginx部署源文件
  5. istio-ingress部署
  6. istio-ingress 使用--profile=default模式就够了
  7. traefik-ingress
posted @ 2022-10-22 12:33  jingjingxyk  阅读(342)  评论(0编辑  收藏  举报