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

10/4/2020

Cluster information:

Installation Method: kubeadm<br> Kubernetes: 1.19.2<br> Master & Nodes: Ubuntu 20.04.1 (Oracle Virutalbox)<br> Docker: 19.03.12<br> Calico: 3.16.1<br> Ingress : Bare-metal - 0.40.1

I want to access the Kubernetes dashboard from my laptop using ingress without proxy?

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".

Updated info:

I have created ingress-controller as daemon instead of deployments/pod - this helps in accessing directly with worker IPs. (this is what I am expecting - but unable to access kubernetes dashboard as it is in different namespace)

Ingress yaml: this is running in default namespace

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

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

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))

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)

192.168.1.31/nginx - responds with nginx default page (pod - nginx-deploy-main)

192.168.1.31/foo - error page - 503 service temporarily Unavailable (default nginx)

192.168.1.31/dashboard - 504 Gateway Time-out (default nginx)

running svc, pods:

All Pods and svcs

-- Muralidhar T
kubernetes
kubernetes-ingress

1 Answer

10/4/2020

If I understand correctly, you want to access kubernetes service (dashboard) from outside cluster. You may deploy metallb LoadBalancer and manage a pull of IPs from external cluster network, assigned to your cluster.

So, you can assign an IP and a LoadBalancer through which you will access your service. Below is an example for mssql server, but you can easily adapt it to your needs with dashboard:

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/

-- mnikolic
Source: StackOverflow