简体   繁体   English

Kubernetes nginx 入口找不到后端服务

[英]Kubernetes nginx ingress cannot find backend service

I have deployed my API to Kubernetes on AKS through kubectl command from my local machine.我已通过本地计算机上的 kubectl 命令将 API 部署到 AKS 上的 Kubernetes。 But the nginx ingress is not able to resolve the backend endpoint.但是 nginx 入口无法解析后端端点。 The ingress logs has an error The service 'hello-world/filter-api' does not have any active endpoint入口日志有错误The service 'hello-world/filter-api' does not have any active endpoint

Steps followed:后续步骤:

Install dapr on AKS在 AKS 上安装 dapr

  • dapr init -k --set global.tag=1.1.2 dapr init -k --set global.tag=1.1.2

Install nginx ingress on AKS在 AKS 上安装 nginx 入口

  • helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx helm repo 添加 ingress-nginx https://kubernetes.github.io/ingress-nginx
  • helm install ingress-nginx ingress-nginx/ingress-nginx -f...\dapr\components\dapr-annotations.yaml --set image.tag=1.11.1 -n ingress-nginx helm install ingress-nginx ingress-nginx/ingress-nginx -f...\dapr\components\dapr-annotations.yaml --set image.tag=1.11.1 -n ingress-nginx

Apply manifest应用清单

  • kubectl apply -f.\services\filter.yaml kubectl apply -f.\services\filter.yaml

What did I try?我尝试了什么?

I tried to deploy this to local Kubernetes cluster on windows with docker desktop.我尝试将其部署到 windows 上的本地 Kubernetes 集群和 docker 桌面。 This works fine.这工作正常。 What am I missing?我错过了什么?

filter.yaml过滤器.yaml

kind: ConfigMap
apiVersion: v1
metadata:
  name: filter-cm
  namespace: hello-world
  labels:
    app: hello-world
    service: filter
data:
  ASPNETCORE_ENVIRONMENT: Development
  ASPNETCORE_URLS: http://0.0.0.0:80
  PATH_BASE: /filter
  PORT: "80"

---

kind: Deployment
apiVersion: apps/v1
metadata:
  name: filter
  namespace: hello-world
  labels:
    app: hello-world
    service: filter
spec:
  replicas: 1
  selector:
    matchLabels:
      service: filter
  template:
    metadata:
      labels:
        app: hello-world
        service: filter
      annotations:
        dapr.io/enabled: "true"
        dapr.io/app-id: "filter-api"
        dapr.io/app-port: "80"
        dapr.io/config: "dapr-config"
    spec:
      containers:
        - name: filter-api
          image: client/hello-world-filter-api:0.0.1
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 80
              protocol: TCP
          envFrom:
            - configMapRef:
                name: filter-cm
      imagePullSecrets:
        - name: regcred

---

apiVersion: v1
kind: Service
metadata:
  name: filter-api
  namespace: hello-world
  labels:
    app: hello-world
    service: filter
spec:
  type: NodePort
  ports:
    - port: 80
      targetPort: 80
      nodePort: 30001
      protocol: TCP
      name: http
  selector:
    service: filter

---

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: filter-ingress
  namespace: hello-world
  labels:
    app: hello-world
    service: filter
spec:
  rules:
  - http:
      paths:
      - path: /filter
        pathType: Prefix
        backend:
          service:
            name: filter-api
            port:
              number: 80

In the service selector, use matchLabels for the service to find the backend pods在服务选择器中,为服务使用 matchLabels 来查找后端 pod

example:例子:

selector:
   matchLabels:
     service: filter

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM