Kubernetes LoadBalancer service on AKS via helm is not accessible

1/26/2019

I'm working on a project in which I need to deploy a simple NodeJs application using Kubernetes, Helm and Azure Kubernetes Service.

Here's What I have tried:

My Dockerfile:

FROM node:8

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE 32000
CMD [ "npm", "start" ]

Here's my mychart/values.yaml:

replicaCount: 1

image:
  # registry: docker.io
  repository: registry-1.docker.io/arycloud/docker-web-app
  tag: 0.3
  pullPolicy: IfNotPresent

nameOverride: ""
fullnameOverride: ""

service:
  name: http
  type: LoadBalancer
  port: 32000
  internalPort: 32000

ingress:
  enabled: false
  annotations: {}
    # kubernetes.io/ingress.class: nginx
    # kubernetes.io/tls-acme: "true"
  paths: []
  hosts:
    - name: mychart.local
      path: /
  tls: []

resources: {}

nodeSelector: {}

tolerations: []

affinity: {}

And my node server.js:

'use strict';

const express = require('express');

// Constants
const PORT = 32000;
const HOST = '0.0.0.0';

// App
const app = express();
app.get('/', (req, res) => {
  res.send('Hello world from container.\n');
});

app.listen(PORT, HOST);
console.log(`Running on http://${HOST}:${PORT}`);

Update: Template files:

From templates/deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "mychart.fullname" . }}
  labels:
    app.kubernetes.io/name: {{ include "mychart.name" . }}
    helm.sh/chart: {{ include "mychart.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "mychart.name" . }}
      app.kubernetes.io/instance: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app.kubernetes.io/name: {{ include "mychart.name" . }}
        app.kubernetes.io/instance: {{ .Release.Name }}
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: 32000
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /
              port: 32000
          readinessProbe:
            httpGet:
              path: /
              port: 32000
            initialDelaySeconds: 3
            periodSeconds: 3
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
    {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
    {{- end }}

From templates/service.yaml:

apiVersion: v1
kind: Service
metadata:
  name: {{ include "mychart.fullname" . }}
  annotations:
    service.beta.kubernetes.io/azure-load-balancer-internal: "true"
  labels:
    app.kubernetes.io/name: {{ include "mychart.name" . }}
    helm.sh/chart: {{ include "mychart.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
  type: {{ .Values.service.type }}
  ports:
    - port: {{ .Values.service.port }}
      targetPort: http
      protocol: TCP
      name: http
  selector:
    app.kubernetes.io/name: {{ include "mychart.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}

Update: a screenshot of external IP: enter image description here Here's the output of `kubectl get svc node-release-mychart -oyaml:

apiVersion: v1
kind: Service
metadata:
  annotations:
    service.beta.kubernetes.io/azure-load-balancer-internal: "true"
  creationTimestamp: "2019-01-26T11:28:27Z"
  labels:
    app.kubernetes.io/instance: node-release
    app.kubernetes.io/managed-by: Tiller
    app.kubernetes.io/name: mychart
    helm.sh/chart: mychart-0.1.0
  name: node-release-mychart
  namespace: default
  resourceVersion: "127367"
  selfLink: /api/v1/namespaces/default/services/node-release-mychart
  uid: 8031f3b6-215d-11e9-bb89-462a1bcec690
spec:
  clusterIP: 10.0.223.27
  externalTrafficPolicy: Cluster
  ports:
  - name: http
    nodePort: 32402
    port: 32000
    protocol: TCP
    targetPort: 32000
  selector:
    app.kubernetes.io/instance: node-release
    app.kubernetes.io/name: mychart
  sessionAffinity: None
  type: LoadBalancer
status:
  loadBalancer:
    ingress:
    - ip: 10.240.0.7

I have created a cluster on AKS then run the get-credentials command from my mac os terminal and it works fine, then I have tagged and pushed my docker image to dockerhub and the docker container is also working fine, after that I have created a helm chart and update the values.yaml accordingly and run the helm install command, it install my application to aks and the service provide an external IP, in the kubernetes dashboard the pods are in running state but when I try to access my application via Etxernal_IP:80 it doesn't load my application.

-- Abdul Rehman
azure
azure-aks
azure-kubernetes
kubernetes
kubernetes-helm

1 Answer

1/26/2019

Your problem comes from the fact you've added the annotation to use internal load balancer (so not exposed publicly, only available inside vnet). To fix that remove this part from the service definition:

annotations:
  service.beta.kubernetes.io/azure-load-balancer-internal: "true"
-- 4c74356b41
Source: StackOverflow