Skip to content

Instantly share code, notes, and snippets.

@DFazeli
Forked from s-lyn/INSTALL.md
Created April 18, 2023 07:06
Show Gist options
  • Save DFazeli/9419dd4c6345076e0873d8f125a394a4 to your computer and use it in GitHub Desktop.
Save DFazeli/9419dd4c6345076e0873d8f125a394a4 to your computer and use it in GitHub Desktop.
Configure Kubernetes Dashboard Web UI hosted with Nginx Ingress Controller

This gist is based on [Kubernetes Dashboard](https://kubernetes.io/docs/tasks/access-application-cluster/web-ui-dashboard/} deploy docs. I think you have installed the Nginx Iingress Controller.

1) Deploy the Dashboard UI

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/aio/deploy/recommended.yaml

2) Creating the Service Account and ClusterRoleBinding

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin-user
  namespace: kubernetes-dashboard
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: admin-user
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: admin-user
  namespace: kubernetes-dashboard
EOF

3) Get a Bearer Token

Now we need to find token we can use to log in. Execute following command:

For Bash:

kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')

For Powershell:

kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | sls admin-user | ForEach-Object { $_ -Split '\s+' } | Select -First 1)

It should print the data with line like:

token: <YOUR TOKEN HERE>

Now save it. You need to use it whe login the dashboard.

4) Create the ingress controller

cat <<EOF | kubectl apply -f -
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  namespace: kubernetes-dashboard
  name: kubernetes-dashboard-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
    nginx.ingress.kubernetes.io/ssl-passthrough: "true"
    # Uncomment next if you use https://cert-manager.io/
    #cert-manager.io/cluster-issuer: "<YOUR CLUSTER ISSUER>"
spec:
  tls:
  - hosts:
    - <YOUR DOMAIN HERE>
    secretName: kubernetes-dashboard-cert
  rules:
  - host: <YOUR DOMAIN HERE>
    http:
      paths:
      - path: /
        backend:
          serviceName: kubernetes-dashboard
          servicePort: 443
EOF

5) Login to dashboard

Go to https://<YOUR DOMAIN> and insert the previous created token into Enter token field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment