kubernetes - 将 Apollo Server 应用程序部署到 GKE 时出现 502 Bad Gateway
问题描述
我正在尝试将我的 Apollo Server 应用程序部署到我的 GKE 集群。但是,当我访问我的站点的静态 IP 时,我收到 502 Bad Gateway 错误。我能够让我的客户以类似的方式正确部署,所以我不确定我做错了什么。我的部署日志似乎显示服务器正常启动。但是,我的入口表明我的服务不健康,因为它似乎没有通过健康检查。
这是我的deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: <DEPLOYMENT_NAME>
labels:
app: <DEPLOYMENT_NAME>
spec:
replicas: 1
selector:
matchLabels:
app: <POD_NAME>
template:
metadata:
name: <POD_NAME>
labels:
app: <POD_NAME>
spec:
serviceAccountName: <SERVICE_ACCOUNT_NAME>
containers:
- name: <CONTAINER_NAME>
image: <MY_IMAGE>
imagePullPolicy: Always
ports:
- containerPort: <CONTAINER_PORT>
- name: cloud-sql-proxy
image: gcr.io/cloudsql-docker/gce-proxy:1.17
command:
- '/cloud_sql_proxy'
- '-instances=<MY_PROJECT>:<MY_DB_INSTANCE>=tcp:<MY_DB_PORT>'
securityContext:
runAsNonRoot: true
我的服务.yml
apiVersion: v1
kind: Service
metadata:
name: <MY_SERVICE_NAME>
labels:
app: <MY_SERVICE_NAME>
annotations:
cloud.google.com/neg: '{"ingress": true}'
spec:
type: NodePort
ports:
- protocol: TCP
port: 80
targetPort: <CONTAINER_PORT>
selector:
app: <POD_NAME>
还有我的 ingress.yml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: <INGRESS_NAME>
annotations:
kubernetes.io/ingress.global-static-ip-name: <CLUSTER_NAME>
networking.gke.io/managed-certificates: <CLUSTER_NAME>
spec:
rules:
- http:
paths:
- path: /*
backend:
serviceName: <SERVICE_NAME>
servicePort: 80
任何想法是什么导致了这个失败?
解决方案
使用 Apollo Server,您需要进行健康检查以查看正确的端点。因此,将以下内容添加到容器下的 deployment.yml 中。
livenessProbe:
initialDelaySeconds: 30
periodSeconds: 30
httpGet:
path: '/.well-known/apollo/server-health'
port: <CONTAINER_PORT>
readinessProbe:
initialDelaySeconds: 30
periodSeconds: 30
httpGet:
path: '/.well-known/apollo/server-health'
port: <CONTAINER_PORT>
推荐阅读
- mysql - 错误 1062 (23000) 中的 sql 注入:重复条目?
- c - 如何解密加密的 ASCII 二进制值?
- gcc - C 代码在带有 Ubuntu 18.04 的虚拟机上编译,而不是在 Crouton 上编译:Struct redef 错误
- python - 如何同时在乌龟中绘制字母?
- ruby-on-rails - 如何避免在 ruby on rails 的嵌套对象上执行 call_back?
- python - 如何在python中将“\u00e3”拉丁字符转换为其正常形式
- swift - 如何在 iOS 设备之间同步 Realm 数据
- c# - 如何让玩家移动到随机的 X 位置?
- angular - RxJS forkJoin 不发射值
- parsing - 使用 (Read a, Show a) 解析二叉树