Thursday, November 21, 2024

Enable ingress

https://blog.raulnq.com/testing-the-nginx-ingress-controller-locally-docker-desktop

 

helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update
helm install nginx-ingress ingress-nginx/ingress-nginx

Run kubectl get ingressclass and kubectl get services to check the installation:

First Deployment 

kubectl create deployment web --image=gcr.io/google-samples/hello-app:1.0

kubectl expose deployment web --type=NodePort --port=8080 

 

Second Deployment  

kubectl create deployment web2 --image=gcr.io/google-samples/hello-app:2.0
kubectl expose deployment web2 --port=8080 --type=NodePort
 

 

 


apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: example-ingress
spec:
  ingressClassName: nginx
  rules:
    - host: hello-world.example
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: web
                port:
                  number: 8080
                  
          - path: /v2
            pathType: Prefix
            backend:
              service:
                name: web2
                port:
                  number: 8080
                  
          - path: /v3
            pathType: Prefix
            backend:
              service:
                name: web
                port:
                  number: 8080

kubectl apply -f example-ingress.yaml 

kubectl get ingress