简体   繁体   English

Kubernetes:在没有主机和代理的情况下通过 Ingress 路由 Kubernetes 仪表板

[英]Kubernetes: Route Kubernetes dashboard through Ingress with out host and without proxy

Cluster information:集群信息:

Installation Method: kubeadm安装方式:kubeadm
Kubernetes: 1.19.2 Kubernetes:1.19.2
Master & Nodes: Ubuntu 20.04.1 (Oracle Virutalbox)主节点和节点:Ubuntu 20.04.1 (Oracle Virutalbox)
Docker: 19.03.12码头工人:19.03.12
Calico: 3.16.1印花布:3.16.1
Ingress : Bare-metal - 0.40.1入口:裸机 - 0.40.1

I want to access the Kubernetes dashboard from my laptop using ingress without proxy?我想在没有代理的情况下使用 ingress 从我的笔记本电脑访问 Kubernetes 仪表板?

Can anyone help me with the steps... ( I tried multiple ways with the help of the internet... not sure where I am missing?)任何人都可以帮助我完成这些步骤......(我在互联网的帮助下尝试了多种方法......不确定我在哪里失踪?)

Note: As per discussion forums I have added "hostNetwork: true" under the deployment section in ingress YAML to resolve "not working without host parameter" and commented "type: NodePort".注意:根据讨论论坛,我在入口 YAML 的部署部分下添加了“hostNetwork:true”以解决“没有主机参数无法工作”并评论“类型:NodePort”。

Updated info:更新信息:

I have created ingress-controller as daemon instead of deployments/pod - this helps in accessing directly with worker IPs.我已经创建了入口控制器作为守护进程而不是部署/pod - 这有助于直接访问工作 IP。 (this is what I am expecting - but unable to access kubernetes dashboard as it is in different namespace) (这是我所期望的 - 但无法访问 kubernetes 仪表板,因为它位于不同的命名空间中)

Ingress yaml: this is running in default namespace Ingress yaml:这是在默认命名空间中运行的

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
    - http:
        paths:
        - path: /
          pathType: Prefix
          backend:
            service:
              name: kdash-in-ns
          port:
            number: 443

kdash-in-ns yaml - svc with External Name kdash-in-ns yaml - 带有外部名称的 svc

kind: Service
apiVersion: v1
metadata:
  name: kdash-in-ns
  namespace: default
spec:
  type: ExternalName
  externalName: kubernetes-dashboard.kubernetes-dashboard.svc.cluster.local
  ports:
  - name: https
    port: 443

Below details about kdash-in-ns svc with ExternalName以下有关带有 ExternalName 的 kdash-in-ns svc 的详细信息

dockeras@ubuntu3:~/simplek8s/kubernetes/yamls/ingress-demo$ kubectl describe svc kdash-in-ns
Name:              kdash-in-ns
Namespace:         default
Labels:            <none>
Annotations:       <none>
Selector:          <none>
Type:              ExternalName
IP:
External Name:     kubernetes-dashboard.kubernetes-dashboard.svc.cluster.local
Port:              https  443/TCP
TargetPort:        443/TCP
Endpoints:         <none>
Session Affinity:  None
Events:            <none>

kubectl describe for the updated ingress route: in this i have ngnix - which is working fine (i guess both ingress and nginx are in same namespace.. getting error for dashboard - as it in different namespace (kubernetes-dasbhoard)) kubectl 描述更新的入口路由:在这个我有 ngnix - 它工作正常(我猜入口和 nginx 都在同一个命名空间中..仪表板出错 - 因为它在不同的命名空间(kubernetes-dasbhoard))

dockeras@ubuntu3:~$ kubectl describe ing nginx-ingress
Warning: extensions/v1beta1 Ingress is deprecated in v1.14+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
Name:             nginx-ingress
Namespace:        default
Address:          192.168.1.31,192.168.1.32
Default backend:  default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
Rules:
  Host        Path  Backends
  ----        ----  --------
  *
              /nginx       nginx-deploy-main:80   )
              /foo         kubernetes-dashboard:443 (<error: endpoints "kubernetes-dashboard" not found>)
              /dashboard   kdash-in-ns:443 (<error: endpoints "kdash-in-ns" not found>)
Annotations:  kubernetes.io/ingress.class: nginx
              nginx.ingress.kubernetes.io/rewrite-target: /$2
Events:
  Type    Reason  Age    From                      Message
  ----    ------  ----   ----                      -------
  Normal  CREATE  4m40s  nginx-ingress-controller  Ingress default/nginx-ingress

When I tried the same URLs in browser below are the responses (One of my worker iP - 192.168.1.31)当我在下面的浏览器中尝试相同的 URL 时,响应是(我的一个工人 iP - 192.168.1.31)

192.168.1.31/nginx - responds with nginx default page (pod - nginx-deploy-main) 192.168.1.31/nginx - 响应 nginx 默认页面(pod - nginx-deploy-main)

192.168.1.31/foo - error page - 503 service temporarily Unavailable (default nginx) 192.168.1.31/foo - 错误页面 - 503 服务暂时不可用(默认 nginx)

192.168.1.31/dashboard - 504 Gateway Time-out (default nginx) 192.168.1.31/dashboard - 504 网关超时(默认 nginx)

running svc, pods:运行 svc,豆荚:

All Pods and svcs所有 Pod 和 svcs

If I understand correctly, you want to access kubernetes service (dashboard) from outside cluster.如果我理解正确,您想从集群外部访问 kubernetes 服务(仪表板)。 You may deploy metallb LoadBalancer and manage a pull of IPs from external cluster network, assigned to your cluster.您可以部署 metallb LoadBalancer 并管理从外部集群网络中提取的 IP,分配给您的集群。

So, you can assign an IP and a LoadBalancer through which you will access your service.因此,您可以分配一个 IP 和一个 LoadBalancer,通过它们您将访问您的服务。 Below is an example for mssql server, but you can easily adapt it to your needs with dashboard:以下是 mssql 服务器的示例,但您可以使用仪表板轻松调整它以满足您的需求:

apiVersion: v1
kind: Service
metadata:
  name: sql-server-lb
  namespace: database-server
  annotations:
    metallb.universe.tf/address-pool: default
spec:
  selector:
    app: sql-server
  ports:
  - port: 1433
    targetPort: 1433
  type: LoadBalancer

https://metallb.universe.tf/ https://metallb.universe.tf/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM