无法通过 helm 访问 AKS 上的 Kubernetes LoadBalancer 服务

Kubernetes LoadBalancer service on AKS via helm is not accessible

我正在做一个项目,我需要使用 Kubernetes、Helm 和 Azure Kubernetes 服务部署一个简单的 NodeJs 应用程序。

这是我尝试过的方法:

我的Dockerfile:

FROM node:8

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . .

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

这是我的 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: {}

我的节点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:

来自 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 }}

来自 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: 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

我在 AKS 上创建了一个集群,然后 运行 来自我的 mac os 终端的 get-credentials 命令并且它工作正常,然后我标记并推送了我的docker 图像到 dockerhub 和 docker 容器也工作正常,之后我创建了一个舵图并相应地更新了 values.yaml 和 运行 helm install 命令,它将我的应用程序安装到 aks 并且服务提供 external IP,在 kubernetes 仪表板中 pods 处于 running 状态但是当我尝试通过 Etxernal_IP:80 访问我的应用程序它不会加载我的应用程序。

您的问题来自于您添加了注释以使用内部负载平衡器(因此未公开公开,仅在 vnet 内部可用)。要修复此问题,请从服务定义中删除此部分:

annotations:
  service.beta.kubernetes.io/azure-load-balancer-internal: "true"