Kubernetes Ingress在Google Kubernetes Engine上获得不健康的后端服务

时间:2018-10-03 12:59:11

标签: docker kubernetes google-kubernetes-engine kubernetes-ingress

我正在尝试在Google容器引擎上部署两个服务,我创建了一个具有3个节点的集群。 我的docker映像位于私有docker hub仓库中,这就是为什么我创建了一个秘密并在Deployments中使用的原因。Ingress在Google云控制台中创建了一个负载均衡器,但是它表明后端服务不是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

更新

这是烧瓶服务代码:

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 :(得分:0)

看看这个post。它可能包含有关您的问题的有用提示。 例如,我在配置文件中确实看到准备就绪探针,但没有发现活跃性探针。

post建议在k8s中“没有最低可用性”可能是由于活动探测失败导致的CrashloopBackoff。

答案 1 :(得分:0)

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