首页 文章

Kubernetes Ingress在Google Kubernetes Engine上获得Unhealthy后端服务

提问于
浏览
0

我为什么创建了一个秘密并在部署中使用,ingress正在谷歌 Cloud 控制台中创建一个负载均衡器,但它显示后端服务不是 healthy ,并且在工作负载下的kubernetes部分中它说 Does not have minimum availability .

我是kubernetes的新手,有什么问题?

这是我的yamls:

Deployment.yaml:

kind: Deployment
apiVersion: apps/v1
metadata:
  name: pythonaryapp
  labels:
    app: pythonaryapp
spec:
  replicas: 1 #We always want more than 1 replica for HA
  selector:
    matchLabels:
      app: pythonaryapp
  template:
    metadata:
      labels:
        app: pythonaryapp
    spec:
      containers:
      - name: pythonaryapp #1st container
        image: docker.io/arycloud/docker_web_app:pythonaryapp #Dockerhub image
        ports:
        - containerPort: 8080 #Exposes the port 8080 of the container
        env:
        - name: PORT #Env variable key passed to container that is read by app
          value: "8080" # Value of the env port.
        readinessProbe:
          httpGet:
            path: /healthz
            port: 8080
          periodSeconds: 2
          timeoutSeconds: 2
          successThreshold: 2
          failureThreshold: 10
      imagePullSecrets:
         - name: docksecret
---

kind: Deployment
apiVersion: apps/v1
metadata:
  name: pythonaryapp1
  labels:
    app: pythonaryapp1
spec:
  replicas: 1 #We always want more than 1 replica for HA
  selector:
    matchLabels:
      app: pythonaryapp1
  template:
    metadata:
      labels:
        app: pythonaryapp1
    spec:
      containers:
      - name: pythonaryapp1 #1st container
        image: docker.io/arycloud/docker_web_app:pythonaryapp1 #Dockerhub image
        ports:
        - containerPort: 8080 #Exposes the port 8080 of the container
        env:
        - name: PORT #Env variable key passed to container that is read by app
          value: "8080" # Value of the env port.
        readinessProbe:
          httpGet:
            path: /healthz
            port: 8080
          periodSeconds: 2
          timeoutSeconds: 2
          successThreshold: 2
          failureThreshold: 10
      imagePullSecrets:
         - name: docksecret
---

这是 services.yaml:

kind: Service
apiVersion: v1
metadata:
  name: pythonaryapp
spec:
  type: NodePort
  selector:
    app: pythonaryapp
  ports:
  - protocol: TCP
    port: 8080
---

---
kind: Service
apiVersion: v1
metadata:
  name: pythonaryapp1
spec:
  type: NodePort
  selector:
    app: pythonaryapp1
  ports:
  - protocol: TCP
    port: 8080
---

这是我的 ingress.yaml:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: mysvcs
spec:
  rules:
  - http:
      paths:
      - path: /
        backend:
          serviceName: pythonaryapp
          servicePort: 8080
      - path: /<name>
        backend:
          serviceName: pythonaryapp1
          servicePort: 8080

Update

这是烧瓶服务代码:

from flask import Flask

app = Flask(__name__)


@app.route('/')
def hello_world():
    return 'Hello World, from Python Service.', 200




if __name__ == '__main__':
    app.run()

并且,在运行它的docker镜像的容器时,它会在根路径 / 处重新调整200 sttaus代码 .

提前致谢!

2 回答

  • 0

    看看这个post . 它可能包含有关您问题的有用提示 . 例如,我确实在配置文件中看到了就绪探测,但没有看到活动探测 .

    这个post表明k8s中“没有最低可用性”可能是由于活动失败探测引起的CrashloopBackoff造成的 .

  • 0

    在GKE中,入口由GCP LoadBalancer实现 . GCP LB通过在服务地址中使用根路径“/”调用服务的 Health 状况来检查服务的 Health 状况 . 确保您的容器可以在根上响应200,或者更改LB后端服务运行状况检查路由(您可以在GCP控制台中执行此操作)

相关问题