2

I have spun up a 3 node Kubernetes cluster (version: 1.5.8) on AWS using the kube-up.sh script following this walkthrough:

https://ryaneschinger.com/blog/building-a-kubernetes-cluster-on-aws/

I'm able to successfully access the cluster and view the UI. Output of kubectl cluster-info command:

enter image description here

I wrote a simple Spring Boot microservice:

@RestController
public class AddCustomerController {

    private static final String template = "Customer %s is added.";

    @RequestMapping("/addcustomer")
    public Message addcustomer(@RequestParam(value="name") String name) {

        //Retrieve the hostname of the "node"/"container"
        String hostname = null;
        try {
            hostname = InetAddress.getLocalHost().getHostName();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }

        return new Message(ThreadLocalRandom.current().nextLong(),
                            String.format(template, name),
                            hostname);
    }
}

and packaged it in a Docker container after the Gradle build and am able to successfully use it locally. I have pushed the image to DockerHub.

FROM openjdk:8-jdk-alpine
VOLUME /tmp
ADD build/libs/*.jar app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

Now I'm using Helm Charts to deploy this application to Kubernetes.

Deployment descriptor:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: add-customer-deployment
spec:
  replicas: 3
  template:
    metadata:
      name: add-customer-microservice
      labels:
        app: add-customer
    spec:
      containers:
      - image: {{ .Values.dockerHubUsername }}/add-customer-microservice:latest
        name: add-customer-microservice
        imagePullPolicy: Always
        ports:
        - containerPort: 8080

Service descriptor:

apiVersion: v1
kind: Service
metadata:
  name: add-customer-service
spec:
  selector:
    app: add-customer
  ports:
    - port: 1000
      protocol: TCP
      targetPort: 8080
      name: access-port
  type: NodePort

I have followed the same procedure for 3 other similar Spring Boot microservices.

Ingress descriptor:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: quantiphi-poc-ingress-dns
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
    - host: crud.qdatalabs.com
      http:
        paths:
        - path: /service1
          backend:
            serviceName: add-customer-service
            servicePort: 1000
        - path: /service1/*
          backend:
            serviceName: add-customer-service
            servicePort: 1000
        - path: /service2
          backend: 
            serviceName: get-customer-service
            servicePort: 2000
        - path: /service2/*
          backend:
            serviceName: get-customer-service
            servicePort: 2000
        - path: /service3
          backend: 
            serviceName: update-customer-service
            servicePort: 3000
        - path: /service3/*
          backend:
            serviceName: update-customer-service
            servicePort: 3000
        - path: /service4
          backend: 
            serviceName: delete-customer-service
            servicePort: 4000
        - path: /service4/*
          backend:
            serviceName: delete-customer-service
            servicePort: 4000

First I install the nginx controller on my cluster using the Helm Charts:

helm install --name my-release stable/nginx-ingress

Then I install my Chart using:

helm install folder-conataining-helm-chart/

Then I point the alias of crud.qdatalabs.com (Type A) from Route53 to the ELB spawned by the Ingress resource.

The URL crud.qdatalabs.com/healthz is giving 200 OK response

When I try to access the microservices using the URL crud.qdatalabs.com/service1/addcustomer?name=starman

I'm treated with the WhiteLabel Error Page:

enter image description here

I think I have made some configuration error, but can't put my finger on it. Please help me with any direction. I'll be happy to provide more details. Thank you.

Akshay
  • 452
  • 1
  • 5
  • 15

1 Answers1

3

As I stated in Setting up a Kuberentes cluster with HTTP Load balancing ingress for RStudio and Shiny results in error pages, the most likely problem you have is that when you go with this ingress you attached your URI is different then with direct accesc ( /service1/ vs / ) so your app is lost and has no content for that uri.

With Nginx Ingress Controller you can use ingress.kubernetes.io/rewrite-target: / annotation to mitigate this and make sure that / is accessed even when there is a subfolder in the ingress path.

So, you either need to use proper rewrite annotation or support the path you use in the ingress inside your service.

Radek 'Goblin' Pieczonka
  • 21,554
  • 7
  • 52
  • 48
  • Hey Radek, thank you so much for your response. I added an echo-server deployment and service to cater to the / path. I'm getting the echo server response when I hit the just the URL crud.qdatalabs.com. However I'm still unable to access my services. I added the ingress.kubernetes.io/rewrite-target: / annotation to my Ingress resource, but I am still getting the same error page. Have I made any mistakes configuring the paths? – Akshay Feb 13 '18 at 09:13
  • 1
    Not sure what ingress controller are you using / how is your cluster provisioned. Newest nginx controller uses `nginx.ingress.kubernetes.io/rewrite-target: /` annotation https://github.com/kubernetes/ingress-nginx/blob/master/docs/user-guide/annotations.md so maybe that is why it is not working for you. – Radek 'Goblin' Pieczonka Feb 13 '18 at 09:28
  • Hey Radek, you are right. I made a typo while adding the annotation! My services are accessible now. Can't thank you enough for your help! – Akshay Feb 13 '18 at 09:35
  • the docu is now located at https://github.com/kubernetes/ingress-nginx/blob/master/docs/examples/rewrite/README.md – Matthias Wiedemann Jun 28 '19 at 11:32