HsinCC987 2025-02-17 10:01 采纳率: 17.6%
浏览 7

KubeSphere 地端k8s 使用 nodeport 如何用 https 訪問 web console?

大家好,
我使用 Kubekey 安裝 K8s,無法使用 Load balancer,請問 nodeport 如何去做 ingress 讓 https 能夠訪問?
我也沒有域名,希望直接用 https:// {IP} 訪問就好

  • 写回答

4条回答 默认 最新

  • 阿里嘎多学长 2025-02-17 10:01
    关注

    阿里嘎多学长整理AIGC生成,因移动端显示问题导致当前答案未能完全显示,请使用PC端查看更加详细的解答过程

    KubeSphere 地端k8s 使用 nodeport 如何用 https 訪問 web console?

    你使用 KubeKey 安裝 K8s,無法使用 Load balancer,想使用 NodePort 來實現 ingress,讓 https 能夠訪問 Web Console。

    解決方案:

    1. 創建 Service
    apiVersion: v1
    kind: Service
    metadata:
      name: web-console
    spec:
      selector:
        app: web-console
      ports:
      - name: https
        port: 443
        targetPort: 8443
      type: NodePort
    

    這個 Service 會將流量轉發到 Pod 的 8443 端口,並將流量Expose 到 NodePort 443。

    1. 創建 Ingress
    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: web-console-ingress
    spec:
      rules:
      - host: <your-node-ip>
        http:
          paths:
          - path: /
            backend:
              serviceName: web-console
              servicePort: 443
    

    這個 Ingress 會將流量轉發到 Service 的 443 端口,並將流量Expose 到 Node 的 IP。

    1. 設置 NodePort
    kubectl get svc web-console -o jsonpath='{.spec.ports[0].nodePort}'
    

    這個命令會顯示 NodePort 的值,例如 30080。

    1. 訪問 Web Console
    https://<your-node-ip>:30080
    

    這樣你就可以使用 https 訪問 Web Console 了。

    注意:這個解決方案假設你已經創建了 Web Console 的 Pod,並且 Pod 的 8443 端口Expose 到 NodePort。

    评论

报告相同问题?

问题事件

  • 创建了问题 2月17日