Unhealthy load balancer on GCE

1/14/2018

I have a couple of services and the loadbalancers work fine. Now I keep facing an issue with a service that runs fine, but when a loadbalancer is applied I cannot get it to work, because one service seams to be unhealty, but I cannot figure out why. How can I get that service healthy?

enter image description here

Here are my k8s yaml. Deployment:

kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  name: api-production
spec:
  replicas: 1
  template:
    metadata:
      name: api
      labels:
        app: api
        role: backend
        env: production
    spec:
      containers:
      - name: api
        image: eu.gcr.io/foobar/api:1.0.0
        livenessProbe:
          httpGet:
            path: /readinez
            port: 8080
          initialDelaySeconds: 45
          periodSeconds: 10
        readinessProbe:
          httpGet:
            path: /healthz
            port: 8080
        env:
        - name: ENVIRONMENT
          value: "production"
        - name: GIN_MODE
          value: "release"
        resources:
          limits:
            memory: "500Mi"
            cpu: "100m"
        imagePullPolicy: Always
        ports:
        - name: api
          containerPort: 8080

Service.yaml

kind: Service
apiVersion: v1
metadata:
  name: api
spec:
  selector:
    app: api
    role: backend
  type: NodePort
  ports:
  - name: http
    port: 8080
  - name: external
    port: 80
    targetPort: 80

Ingress.yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: api
  namespace: production
  annotations:
    kubernetes.io/tls-acme: "true"
    kubernetes.io/ingress.class: "gce"
spec:
  tls:
  - hosts:
    - foo.bar.io
    secretName: api-tls
  rules:
  - host: foo.bar.io
    http:
      paths:
      - path: /*
        backend:
          serviceName: api
          servicePort: 80
-- Tino
google-cloud-platform
google-kubernetes-engine
kubernetes

1 Answer

1/19/2018

The problem was solved by configuring the ports in the correct way. Container, Service and LB need (obviously) to be aligned. I also added the initialDelaySeconds.

LB:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: api
  namespace: production
  annotations:
    # kubernetes.io/ingress.allow-http: "false"
    kubernetes.io/tls-acme: "true"
    kubernetes.io/ingress.class: "gce"
spec:
  tls:
  - hosts:
    - api.foo.io
    secretName: api-tls
  rules:
  - host: api.foo.io
    http:
      paths:
      - path: /*
        backend:
          serviceName: api
          servicePort: 8080 

Service:

kind: Service
apiVersion: v1
metadata:
  name: api
spec:
  selector:
    app: api
    role: backend
  type: NodePort
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8080
      name: http 

Deployment:

kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  name: api-production
spec:
  replicas: 1
  template:
    metadata:
      name: api
      labels:
        app: api
        role: backend
        env: production
    spec:
      containers:
      - name: api
        image: eu.gcr.io/foobarbar/api:1.0.0
        livenessProbe:
          httpGet:
            path: /readinez
            port: 8080
          initialDelaySeconds: 45
          periodSeconds: 10
        readinessProbe:
          httpGet:
            path: /healthz
            port: 8080
          initialDelaySeconds: 45
        env:
         - name: ENVIRONMENT
          value: "production"
        - name: GIN_MODE
          value: "release"
        resources:
          limits:
            memory: "500Mi"
            cpu: "100m"
        imagePullPolicy: Always
        ports:
        - containerPort: 8080
-- Tino
Source: StackOverflow