配置 Kubernetes Ingress

配置 Kubernetes Ingress

我正在尝试将 Google Kubernetes Engine Ingress 正确配置到在端口 3000 上运行的负载平衡 Docker 应用程序。我显然在某个地方犯了一个明显的错误,但我不知道在哪里。Ingress 总是说机器不健康,但我能够验证 Web 应用程序是否正在运行并在 0.0.0.0:3000 上监听。

除了所述问题之外,我还希望了解我的配置中存在的任何其他明显缺陷。

当前设置如下:

部署.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
spec:
  replicas: 1
  selector:
    matchLabels:
      app: web
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
  minReadySeconds: 5
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
      - name: cloud-sql-proxy
        image: gcr.io/cloudsql-docker/gce-proxy:1.17
        command:
          - "/cloud_sql_proxy"
          - "-ip_address_types=PRIVATE"
          - "-instances=project:us-central1:postgres=tcp:5432"
        securityContext:
          runAsNonRoot: true
      - name: web
        image: gcr.io/PROJECT_ID/IMAGE:TAG
        ports:
        - containerPort: 3000
        env:
        - name: MASTER_KEY
          valueFrom:
            secretKeyRef:
              name: masterkey
              key: MASTER_KEY
        resources:
          requests:
            cpu: 100m
          limits:
            cpu: 100m

web 服务.yml

apiVersion: v1
kind: Service
metadata:
  name: web-service
spec:
  selector:
    app: web
  type: NodePort
  ports:
    - port: 3000
      targetPort: 443
      protocol: TCP
      name: https

web-ingress.yml

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: web-ingress
  annotations:
    kubernetes.io/ingress.global-static-ip-name: staging-cluster
    networking.gke.io/managed-certificates: cloudflare-origin
spec:
  rules:
  - host: staging.mydomain.com
    http:
      paths:
      - backend:
        serviceName: web-service
        servicePort: 443

cloudflare-origin.yml*

apiVersion: networking.gke.io/v1beta2
kind: ManagedCertificate
metadata:
  name: cloudflare-origin
spec:
  domains:
    - staging.mydomain.com

计算地址.yml

apiVersion: compute.cnrm.cloud.google.com/v1beta1
kind: ComputeAddress
metadata:
  name: staging-cluster
spec:
  location: global

kustomization.yml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- gke/deployment.yml
- gke/config-connector.yml
- gke/compute-address.yml
- gke/cloudflare-origin.yml
- gke/web-service.yml
- gke/web-ingress.yml

答案1

在您的入口资源中,您使用服务端口:443,但在您的服务定义中您有端口:3000。

您需要按如下方式修复您的服务:

apiVersion: v1
kind: Service
metadata:
  name: web-service
spec:
  selector:
    app: web
  type: NodePort
  ports:
    - port: 443
      targetPort: 3000
      protocol: TCP
      name: https

相关内容