Microk8s: [Help needed] Can鈥檛 access Endpoint of Springboot webservice from ingress

Created on 4 Jun 2019  路  7Comments  路  Source: ubuntu/microk8s

Hi Everyone,

I tried to set up a quick microK8s cluster on my local machine to introduce Kubernetes in a meetup on my company. So I create a little helloworld webservice with Springboot with 2 entrypoints and some actuator entrypoints

I deployed my app on my microk8s cluster with some resources yaml files:

This is my microk8s configuration:

microk8s.kubectl version
Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.1", GitCommit:"b7394102d6ef778017f2ca4046abbaa23b88c290", GitTreeState:"clean", BuildDate:"2019-04-08T17:11:31Z", GoVersion:"go1.12.1", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.1", GitCommit:"b7394102d6ef778017f2ca4046abbaa23b88c290", GitTreeState:"clean", BuildDate:"2019-04-08T17:02:58Z", GoVersion:"go1.12.1", Compiler:"gc", Platform:"linux/amd64"}

```bash
microk8s.status --yaml
microk8s:
running: true
addons:
jaeger: disabled
fluentd: disabled
gpu: disabled
storage: disabled
registry: disabled
ingress: enabled
dns: enabled
metrics-server: disabled
prometheus: disabled
istio: disabled
dashboard: enabled

And my app configuration:

- Ingress

```bash
microk8s.kubectl describe ingress hello-world-ingress
Name:             hello-world-ingress
Namespace:        default
Address:          
Default backend:  default-http-backend:80 (<none>)
Rules:
  Host       Path  Backends
  ----       ----  --------
  localhost  
             /*   hello-world-service:81 (10.1.1.19:8080,10.1.1.20:8080)
Annotations:
  kubectl.kubernetes.io/last-applied-configuration:  {"apiVersion":"networking.k8s.io/v1beta1","kind":"Ingress","metadata":{"annotations":{"ingress.kubernetes.io/rewrite-target":"/*","kubernetes.io/ingress.class":"nginx-int"},"name":"hello-world-ingress","namespace":"default"},"spec":{"rules":[{"host":"localhost","http":{"paths":[{"backend":{"serviceName":"hello-world-service","servicePort":81},"path":"/*"}]}}]}}

  kubernetes.io/ingress.class:           nginx-int
  ingress.kubernetes.io/rewrite-target:  /*
Events:                                  <none>
  • Service
microk8s.kubectl describe service hello-world-service
Name:              hello-world-service
Namespace:         default
Labels:            app=hello-world
Annotations:       kubectl.kubernetes.io/last-applied-configuration:
                     {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"hello-world"},"name":"hello-world-service","namespace":"...
Selector:          app=hello-world
Type:              ClusterIP
IP:                10.152.183.140
Port:              hello-world  81/TCP
TargetPort:        8080/TCP
Endpoints:         10.1.1.19:8080,10.1.1.20:8080
Session Affinity:  None
Events:            <none>
  • Deployment
microk8s.kubectl describe deployment hello-world-deployment
Name:                   hello-world-deployment
Namespace:              default
CreationTimestamp:      Wed, 29 May 2019 10:52:07 +0200
Labels:                 <none>
Annotations:            deployment.kubernetes.io/revision: 5
                        kubectl.kubernetes.io/last-applied-configuration:
                          {"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{},"name":"hello-world-deployment","namespace":"default"},"spec":{"r...
Selector:               app=hello-world
Replicas:               3 desired | 3 updated | 3 total | 2 available | 1 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  1 max unavailable, 0 max surge
Pod Template:
  Labels:  app=hello-world
           env=prod
           version=0.2.0-SNAPSHOT
  Containers:
   hello-world:
    Image:      winael/hello-world:0.2.0-SNAPSHOT
    Port:       8080/TCP
    Host Port:  0/TCP
    Limits:
      cpu:     500m
      memory:  200Mi
    Requests:
      cpu:        100m
      memory:     100Mi
    Liveness:     http-get http://:8080/actuator/health delay=120s timeout=1s period=10s #success=1 #failure=3
    Readiness:    http-get http://:8080/actuator/health delay=120s timeout=1s period=10s #success=1 #failure=3
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    NewReplicaSetAvailable
OldReplicaSets:  <none>
NewReplicaSet:   hello-world-deployment-899dffddb (3/3 replicas created)
Events:          <none>

When I call an endpoint to the webservice using the IP defined in the service resource (10.152.183.140) on port 81, it's working fine, but when I try to call it from localhost on port 80 as it is defined on Ingress, I have a default backend - 404

I suppose I didn't set correctly my ingress but don't understand what's happening. Can someone help me on this ?

Regards,
Winael

inspection-report-20190604_101612.tar.gz

Most helpful comment

You can have a cluster with multiple nginx ingress controllers. Each serving different tenants.
But frankly, i have not tried running multilple nginx ingress controllers.馃榿

Since microk8s does not specify the ingress-class in the ingress.yaml, then you dont need to specify the ingress-class annotation as well. That's why removing the annotation works.

All 7 comments

@Winael can you try this ingress:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: hello-world-ingress
spec:
  rules:
  - host: localhost
    http:
      paths:
      - backend:
          serviceName: hello-world-service
          servicePort: 81
        path: /greeting

And point your browser to http://localhost/greeting

I am not sure what that annotation I removed does exactly.

You can have a cluster with multiple nginx ingress controllers. Each serving different tenants.
But frankly, i have not tried running multilple nginx ingress controllers.馃榿

Since microk8s does not specify the ingress-class in the ingress.yaml, then you dont need to specify the ingress-class annotation as well. That's why removing the annotation works.

Oh thx for your answer. Effectively it seems better. I'll redeploy correctly my app as soon as I home to test it. Thx a lots :)

It works perfectly

Thx for your help and thx @balchua for your explanation. It's very useful to understand what's happened and learn from my mistakes :)

Effectively, I was inspired by ingress we used at work, but we have multi tenant k8s cluster (one tenant for each SAFe Streams). So I suppose that our K8s Administration team set multiple nginx controllers to do that.

Thx to you I have now a better understanding about how Ingress works :)

Cheers

Good to hear. Cheers.

@winael you're most welcome! 馃榿

@Winael you're most welcome! 馃榿

Yours worked for me in Development. I was using MicroK8s

Was this page helpful?
0 / 5 - 0 ratings