0
votes

Stack: Azure Kubernetes Service
NGINX Ingress Controller - https://github.com/kubernetes/ingress-nginx
AKS Loadbalancer
Docker containers

My goal is to create a K8s cluster that will allow me to use multiple pods, under a single IP, to create a microservice architecture. After working with tons of tutorials and documentation, I'm not having any luck with my endgoal. I got to the point of being able to access a single deployment using the Loadbalancer, but introducing the ingress has not been successful so far. The services are separated into their respective files for readability and ease of control.

Additionally, the Ingress Controller was added to my cluster as described in the installation instructions using: kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.35.0/deploy/static/provider/cloud/deploy.yaml

LoadBalancer.yml:

apiVersion: v1
kind: Service
metadata:
  name: backend
spec:
  loadBalancerIP: x.x.x.x
  selector:
    app: ingress-service
    tier: backend
  ports:
  - name: "default"
    port: 80
    targetPort: 80
  type: LoadBalancer

IngressService.yml:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: ingress-service
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
  - http:
      paths:
      - path: /api
        backend:
          serviceName: api-service
          servicePort: 80

api-deployment.yml

apiVersion: v1
kind: Service
metadata:
  name: api-service
spec:
  selector:
    app: api
  ports:
    - port: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
   name: api-deployment
spec:
  selector:
    matchLabels:
      app: api
      tier: backend
      track: stable
  replicas: 1
  template:
    metadata:
      labels:
        app: api
        tier: backend
        track: stable
    spec:
      containers:
      - name: api
        image: image:tag
        ports:
        - containerPort: 80
        imagePullPolicy: Always
      imagePullSecrets:
      - name: SECRET

The API in the image is exposed on port 80 correctly.

After applying each of the above yml services and deployments, I attempt a web request to one of the api resources via the LoadBalancer's IP and receive only a timeout on my requests.

1
why do you need loadbalancer.yaml? ingress deployment has load balalncer in it already, just use that existing lb and access the IP of the lb. also, I dont see a hostname under your ingress, not sure that should work4c74356b41
If I'm not using an Azure Loadbalancer, how do I set the IP to send my requests through?Carson
if you are not - probably no easy way, node port and public ip for each node. very fragile4c74356b41

1 Answers

1
votes

Found my answer after hunting around enough. Basically, the problem was that the Ingress Controller has a Load Balancer built into the yaml, as mentioned in comments above. However, the selector for that LoadBalancer requires marking your Ingress service as part of the class. Then that Ingress service points to each of the services attached to your pods. I also had to make a small modification to allow using a static IP in the provided load balancer.