1
votes

I have created two services and then tried to create Ingress in GKE. My intention is to create ingress with loadbalancer http/https load balancer, from the course I have read that ingress creates load balancer. I created a static ip for loadbalancer which is part of annotations.

Both services are created succesfully and ingress is also created but ingress doesn't have any hosts or 'address' .

Following are cluster services...

Service definition.. same for service 2 except service name change...

apiVersion: v1
kind: Service
metadata:
  name: dns-demo
spec:
  selector:
    name: dns-demo
  clusterIP: None
  ports:
  - name: dns-demo
    port: 1234
    targetPort: 1234
---
apiVersion: v1
kind: Pod
metadata:
  name: dns-demo-1
  labels:
    name: dns-demo
spec:
  hostname: dns-demo-1
  subdomain: dns-demo
  containers:
  - name: nginx
    image: nginx
---
apiVersion: v1
kind: Pod
metadata:
  name: dns-demo-2
  labels:
    name: dns-demo
spec:
  hostname: dns-demo-2
  subdomain: dns-demo
  containers:
  - name: nginx
    image: nginx

Ingress Definition...

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: hello-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
    kubernetes.io/ingress.global-static-ip-name: "global-ingress"
spec:
  rules:
  - http:
      paths:
      - path: /v1
        backend:
          serviceName: hello-svc
          servicePort: 80
      - path: /v2
        backend:
          serviceName: hello-lb-svc
          servicePort: 80

Can you please let me know what wrong am I doing ?

Thanks

1

1 Answers

1
votes

There is a simple and good tutorial explaining how to achieve this here.

IN your setup I see a few things that need to be corrected. The first and most important is that you used the option clusterIP: None and it makes your service inaccessible to the Ingress.

Here is an image explaining how ingress works.

Ingress FlowSource

Ingress is going to redirect all the traffic to your service and your service must be Type NodePort or LoadBalancer in order to be able to receive this traffic.

Second problem is that your service is pointing to port 1234 but your pods are running NGINX and it is listening on port 80.

Your service should look like this (tested):

apiVersion: v1
kind: Service
metadata:
  name: dns-demo
spec:
  type: NodePort
  selector:
    name: dns-demo
  ports:
  - name: dns-demo
    port: 80
    targetPort: 80     

We can now get into your ingress and here I see more problems.

First problem is that you have set backend: serviceName: hello-svc and hello-lb-svc but your service name is dns-demo. So when a request is made to your ingress, it doesn't know where to send the traffic as the backend doesn't exist.

You also used a few annotations that are not necessary at this point. A simple ingress rule for your case may look like this (tested):

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: dns-demo
spec:
  backend:
    serviceName: dns-demo
    servicePort: 80

At the end, your full manifest may look like this:

apiVersion: v1
kind: Pod
metadata:
  name: dns-demo-1
  labels:
    name: dns-demo
spec:
  hostname: dns-demo-1
  subdomain: dns-demo
  containers:
  - name: nginx
    image: nginx
---
apiVersion: v1
kind: Pod
metadata:
  name: dns-demo-2
  labels:
    name: dns-demo
spec:
  hostname: dns-demo-2
  subdomain: dns-demo
  containers:
  - name: nginx
    image: nginx    
---
apiVersion: v1
kind: Service
metadata:
  name: dns-demo
spec:
  type: NodePort
  selector:
    name: dns-demo
  ports:
  - name: dns-demo
    port: 80
    targetPort: 80      
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: dns-demo
spec:
  backend:
    serviceName: dns-demo
    servicePort: 80