miércoles, 18 de septiembre de 2024

Add an ingress for the kubernetes dashboard

Run the following command to install the dashboard:

[ec2-user@ip-172-31-80-45 k8s-demo]minikube dashboard


Enable the ingress controller:

[ec2-user@ip-172-31-80-45 ~]$ minikube addons enable ingress

💡  ingress is an addon maintained by Kubernetes. For any concerns contact minikube on GitHub.

You can view the list of minikube maintainers at: https://github.com/kubernetes/minikube/blob/master/OWNERS

    ▪ Using image registry.k8s.io/ingress-nginx/controller:v1.11.2

    ▪ Using image registry.k8s.io/ingress-nginx/kube-webhook-certgen:v1.4.3

    ▪ Using image registry.k8s.io/ingress-nginx/kube-webhook-certgen:v1.4.3

🔎  Verifying ingress addon...

🌟  The 'ingress' addon is enabled


Create a YAML file:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: dashboard-ingress
namespace: kubernetes-dashboard
spec:
defaultBackend:
service:
name: kubernetes-dashboard
port:
number: 80


Apply the ingress to the cluster:

[ec2-user@ip-172-31-80-45 k8s-demo]$ kubectl apply -f dashboard-ingress.yaml 

ingress.networking.k8s.io/dashboard-ingress created


Check the namespaces:

[ec2-user@ip-172-31-80-45 ~]$ kubectl get ns

NAME                   STATUS   AGE

default                Active   2d22h

ingress-nginx          Active   2d15h

kube-node-lease        Active   2d22h

kube-public            Active   2d22h

kube-system            Active   2d22h

kubernetes-dashboard   Active   41h


Check the ingress service for the namespace:

[ec2-user@ip-172-31-80-45 k8s-demo]$ kubectl get ingress -n kubernetes-dashboard

NAME                CLASS   HOSTS   ADDRESS        PORTS   AGE

dashboard-ingress   nginx   *       192.168.49.2   80      40h


Add proper iptables rules to forward the traffic:

[ec2-user@ip-172-31-80-45 k8s-demo]$ sudo iptables -A PREROUTING -t nat -i enX0 -p tcp --dport 80 -j DNAT --to-destination 192.168.49.2:80

sudo iptables -A FORWARD -p tcp -d 192.168.49.2 --dport 80 -j ACCEPT




[ec2-user@ip-172-31-80-45 ~]$ kubectl describe ingress dashboard-ingress -n kubernetes-dashboard

Name:             dashboard-ingress

Labels:           <none>

Namespace:        kubernetes-dashboard

Address:          192.168.49.2

Ingress Class:    nginx

Default backend:  kubernetes-dashboard:80 (10.244.0.40:9090)

Rules:

  Host        Path  Backends

  ----        ----  --------

  *           *     kubernetes-dashboard:80 (10.244.0.40:9090)

Annotations:  <none>

Events:

  Type    Reason  Age                    From                      Message

  ----    ------  ----                   ----                      -------

  Normal  Sync    8m29s (x3 over 9m29s)  nginx-ingress-controller  Scheduled for sync




After that you can access with the web browser using the public dns name.


After you test it, you can remove the ingress:

[ec2-user@ip-172-31-80-45 ~]$ kubectl delete ingress dashboard-ingress -n kubernetes-dashboard

ingress.networking.k8s.io "dashboard-ingress" deleted




No hay comentarios:

Publicar un comentario