paulbouwer / hello-kubernetes

Provides a demo app to deploy to a Kubernetes cluster. It displays a message, the name of the pod and details of the node it's deployed to.
MIT License
413 stars 508 forks source link

Ingress example not working #31

Open kimllee opened 2 years ago

kimllee commented 2 years ago

Hello,

The ingress example isn't working because now the api used is the networking v1 and the syntax doesn't seem to be recognized Tested with GKE 1.21.5 Thank you.

Name:             hello-kubernetes-ingress
Namespace:        hello-kubernetes
Address:          
Default backend:  default-http-backend:80 (10.20.0.7:8080)
TLS:
  hello-prod terminates XXXXXXXXXXX
Rules:
  Host        Path  Backends
  ----        ----  --------
  *           
              /hello-world(/|$)(.*)   hello-kubernetes-hello-world:80 (10.20.0.31:8080,10.20.1.30:8080)
Annotations:  acme.cert-manager.io/http01-edit-in-place: true
              cert-manager.io/cluster-issuer: letsencrypt
              kubernetes.io/ingress.class: nginx
              nginx.ingress.kubernetes.io/rewrite-target: /$2
Events:
  Type     Reason          Age                   From                      Message
  ----     ------          ----                  ----                      -------
  Warning  Rejected        <invalid>             nginx-ingress-controller  hello-kubernetes/hello-kubernetes-ingress was rejected: with error: spec.rules[0].host: Required value
  Warning  Rejected        <invalid>             nginx-ingress-controller  hello-kubernetes/hello-kubernetes-ingress was rejected: with error: spec.rules[0].host: Required value
  Warning  Rejected        <invalid>             nginx-ingress-controller  spec.rules[0].host: Required value
  Warning  Rejected        <invalid>             nginx-ingress-controller  spec.rules[0].host: Required value
dcorbe commented 2 years ago

The ingress example probably shouldn't be there at all as Ingress configuration is typically cluster-specific.

frayos commented 2 years ago

My adapted / working example on K3S 1.23

# hello-kubernetes-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: hello-kubernetes-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  rules:
  - http:
      paths:
      - pathType: Prefix #Exact
        backend:
          service:
             name: hello-kubernetes-hello-world
             port: 
              number: 80
        path: /hello-world(/|$)(.*)
      - pathType: Prefix #Exact   
        backend:
          service:
             name: hello-kubernetes-custom-message
             port: 
                number: 80
        path: /custom-message(/|$)(.*)