V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Flands
V2EX  ›  Kubernetes

k8s 的 traefik pod 如何暴露 80 443 端口?

  •  
  •   Flands · 2020-03-10 01:43:21 +08:00 · 5241 次点击
    这是一个创建于 1502 天前的主题,其中的信息可能已经有所发展或是发生改变。

    在 k8s 内搭建 traefik,想把 80\443 端口暴露到主机上,使用 helm 搭建时可以做到,但是自己配置添加了
    hostNetwork: true 无效。 helm 搭建的 traefik 的 service 里,在 k8s dashboard 里可以看到,外部端点是有显示

    localhost:80
    localhost:443
    

    并且在主机上可以直接访问

    traefik-deploy.yaml

    apiVersion: v1
    kind: Service
    metadata:
      name: traefik
      namespace: kube-system
    spec:
      ports:
        - name: web
          protocol: TCP
          nodePort: 30080
          port: 80
          targetPort: http
        - name: websecure
          protocol: TCP
          nodePort: 30443
          port: 443
        - name: admin
          port: 8080
          nodePort: 30880
      selector:
        app: traefik
      type: NodePort
    ---
    apiVersion: apps/v1
    kind: DaemonSet
    metadata:
      name: traefik-ingress-controller
      namespace: kube-system
      labels:
        app: traefik
    spec:
      selector:
        matchLabels:
          app: traefik
      template:
        metadata:
          name: traefik
          labels:
            app: traefik
        spec:
          serviceAccountName: traefik-ingress-controller
          terminationGracePeriodSeconds: 1
          hostNetwork: true
          containers:
            - image: traefik:v2.1.6
              name: traefik-ingress-lb
              ports:
                - name: http
                  containerPort: 80
                  hostPort: 80           #hostPort 方式,将端口暴露到集群节点
                - name: https
                  containerPort: 443
                  hostPort: 443          #hostPort 方式,将端口暴露到集群节点
                - name: admin
                  containerPort: 8080
              resources:
                limits:
                  cpu: 2000m
                  memory: 1024Mi
                requests:
                  cpu: 1000m
                  memory: 1024Mi
              securityContext:
                capabilities:
                  drop:
                    - ALL
                  add:
                    - NET_BIND_SERVICE
              args:
                - --configfile=/config/traefik.yaml
              volumeMounts:
                - mountPath: "/config"
                  name: "config"
          volumes:
            - name: config
              configMap:
                name: traefik-config 
          tolerations:              #设置容忍所有污点,防止节点被设置污点
            - operator: "Exists"
          nodeSelector:             #设置 node 筛选器,在特定 label 的节点上启动
            IngressProxy: "true"
    

    搜了一圈文档都没发现怎么做到的,求助一下各位大佬。谢谢

    4 条回复    2020-03-10 15:10:57 +08:00
    binux
        1
    binux  
       2020-03-10 02:05:14 +08:00 via Android
    bind IP address
    hzfyjgw
        2
    hzfyjgw  
       2020-03-10 09:16:39 +08:00
    可以考虑用 nodeselector 的有特定标签的 daemonset 的形式部署 traefik
    Flands
        3
    Flands  
    OP
       2020-03-10 13:26:06 +08:00
    @hzfyjgw 看 yaml 是 DaemonSet 方式部署的
    Flands
        4
    Flands  
    OP
       2020-03-10 15:10:57 +08:00
    service 里 type: LoadBalancer 就好了。。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2754 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 05:44 · PVG 13:44 · LAX 22:44 · JFK 01:44
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.