我正在学习如何使用Ingress在Google Kubernetes Engine上公开我的应用程序。我遵循了一些教程,并对所需内容进行了粗略的设置。但是,我不知道为什么尽管可以从我直接定义的NodePort服务访问它们,但我的服务仍被标记为不正常。
这是我的部署文件:(我删除了一些数据,但大部分保持不变)
--
apiVersion: "apps/v1"
kind: "Deployment"
metadata:
name: "deployment-1"
namespace: "default"
spec:
containers:
- name: myContainer
image: "myImage/"
readinessProbe:
httpGet:
path: /app1
port: 8080
initialDelaySeconds: 70
livenessProbe:
httpGet:
path: /app1
port: 8080
initialDelaySeconds: 70
ports:
- containerPort: 8080
protocol: TCP
volumeMounts:
- mountPath: opt/folder/libs/jdbc/
name: lib
volumes:
- name: lib
persistentVolumeClaim:
claimName: lib
---
如我所读,我需要一个ReadinessProbe和LivinessProbe才能使GKE在我定义的路径上运行健康检查,并通过使用我自己定义的路径显示为/ app1(此处将返回200 OK),生成的健康检查应通过。我为图像中运行的tomcat服务器的启动时间设置了70s的初始延迟。
接下来,我创建了一个NodePort服务作为Ingress的后端: 我通过连接到该服务的节点的公共IP和节点端口进行了测试,该服务成功运行。
---
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
ports:
- name: my-port
port: 8080
protocol: TCP
targetPort: 8080
selector:
app: deployment-1
type: NodePort
,然后是Ingress清单文件:
在这里,我保留了名称为“ gke-my-static-ip”的静态IP地址,并创建了域名为“ mydomain.web.com”的ManagedCertificate“ gke-my-certificate”。还已在DNS记录中配置了此地址,使其指向该保留的静态IP。
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: gke-my-ingress-1
annotations:
kubernetes.io/ingress.global-static-ip-name: gke-my-static-ip
networking.gke.io/managed-certificates: gke-my-certificate
spec:
rules:
- host: mydomain.web.com
http:
paths:
- backend:
serviceName: my-service
servicePort: my-port
默认情况下,Ingress会创建2个后端,一个在/ healthz路径上,另一个在我的自定义路径/ app1下。 healthz路径返回200 OK,但是我自定义的路径无法连接。我检查了防火墙规则,并允许端口tcp30000-32767。
在检查堆栈驱动程序时,运行状况检查尝试使用/ app1路径访问我的LoadBalancer的IP,但它似乎总是返回502错误。
我是否缺少设置中的任何步骤?
附加的入口,端点:
NAME HOSTS ADDRESS PORTS AGE
ingress.extensions/gke-my-ingress-1 mydomain.web.com <IP_ADDRESS> 80 3d15h
NAME ENDPOINTS AGE
endpoints/kubernetes <IP_ADDRESS>443 9d
endpoints/presales-service <IP_ADDRESS>:8080 4d16h
kubectl获取入口:
Name: gke-my-ingress-1
Namespace: default
Address: <IP_ADDRESS>
Default backend: default-http-backend:80 (<IP_ADDRESS>)
Rules:
Host Path Backends
---- ---- --------
mydomain.web.com
/ my-service:my-port (<IP_ADDRESS>:8080)
Annotations:
ingress.kubernetes.io/target-proxy: k8s-tp-default-gke-my-ingress-1--d8d0fcf4484c1dfd
ingress.kubernetes.io/url-map: k8s-um-default-gke-my-ingress-1--d8d0fcf4484c1dfd
kubernetes.io/ingress.global-static-ip-name: gke-my-static-ip
networking.gke.io/managed-certificates: gke-my-certificate
ingress.gcp.kubernetes.io/pre-shared-cert: mcrt-e7dd5612-e6b4-42ca-91c9-7d9a86abcfb2
ingress.kubernetes.io/forwarding-rule: k8s-fw-default-gke-my-ingress-1--d8d0fcf4484c1dfd
ingress.kubernetes.io/ssl-cert: mcrt-e7dd5612-e6b4-42ca-91c9-7d9a86abcfb2
kubectl.kubernetes.io/last-applied-configuration: {"apiVersion":"extensions/v1beta1","kind":"Ingress","metadata":{"annotations":{"kubernetes.io/ingress.global-static-ip-name":"gke-my-static-ip","networking.gke.io/managed-certificates":"gke-my-certificate"},"name":"gke-my-ingress-1","namespace":"default"},"spec":{"rules":[{"host":"mydomain.web.com","http":{"paths":[{"backend":{"serviceName":"my-service","servicePort":"my-port"},"path":"/"}]}}]}}
ingress.kubernetes.io/backends: {"k8s-be-30242--d8d0fcf4484c1dfd":"HEALTHY","k8s-be-30310--d8d0fcf4484c1dfd":"UNHEALTHY"}
ingress.kubernetes.io/https-forwarding-rule: k8s-fws-default-gke-my-ingress-1--d8d0fcf4484c1dfd
ingress.kubernetes.io/https-target-proxy: k8s-tps-default-gke-my-ingress-1--d8d0fcf4484c1dfd
答案 0 :(得分:2)
通过修改“就绪和活力”探针,添加了successThreshold和FailureThreshold,我设法使Ingress正常工作。可能是因为我的应用程序需要更多的缓冲时间才能运行。
readinessProbe:
httpGet:
path: /app1/
port: 8080
periodSeconds: 5
timeoutSeconds: 60
successThreshold: 1
failureThreshold: 3
initialDelaySeconds: 70
livenessProbe:
httpGet:
path: /app1/
port: 8080
periodSeconds: 5
timeoutSeconds: 60
successThreshold: 1
failureThreshold: 3
initialDelaySeconds: 70