Kubernetes Dashboard在集群外部访问

时间:2019-11-12 13:01:45

标签: kubernetes kubernetes-ingress kubernetes-dashboard

我们有一个kubernetes环境(3个EC2实例)。我正在尝试从群集外部访问仪表板,但无法访问其显示站点。这样我就转到了一些链接,并通过nginx-ingress找到了我们可以访问的链接。

I have gone to this url并安装了nginx。

我已经创建了该文件以供访问。

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    ingress.kubernetes.io/ssl-passthrough: "true"
    nginx.org/ssl-backends: "kubernetes-dashboard"
    kubernetes.io/ingress.allow-http: "false"
    nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
  name: dashboard-ingress
  namespace: kube-system
spec:
  rules:
  - host: serverdnsname
    http:
      paths:
      - path: /dashboard
        backend:
          serviceName: kubernetes-dashboard
          servicePort: 443

但仍然无法访问它。

2 个答案:

答案 0 :(得分:1)

我们这样管理它

kind: Service
apiVersion: v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kube-system
spec:
  ports:
    - port: 80
      targetPort: 9090
  selector:
    k8s-app: kubernetes-dashboard

只是添加了一个clusterip服务,并在其之前使用nginx作为反向代理

server {
    listen 443 ssl http2;
    server_name kubernetes.dev.xxxxx;

    ssl_certificate /etc/letsencrypt/live/kubernetes.dev.xxxx/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/kubernetes.dev.xxxx/privkey.pem;

    include ssl.conf;

    location / {
        deny all;
        include headers.conf;

        resolver 10.96.0.10 valid=30s; #ip of your dns service inside the cluster
        set $upstream kubernetes-dashboard.kube-system.svc.cluster.local;
        proxy_pass http://$upstream;
    }
}

但使用NodePort也应该可以实现

答案 1 :(得分:0)

我没有使用Ingress进行尝试,但是您可能知道,作为一种快速但不一定是好的解决方案,您还可以将其公开为NodePort吗?