我正在使用 initContainer 挂载 index.html 并将其挂载在 tomcat 9 服务器中。
readinessProbe
, 输入:httpGet
初始延迟秒数:60。
没有 readinessProbe,应用程序启动,我可以访问 Url 并查看内容。
kubectl describe pod/<pod-->
提供以下消息
Normal Created 104s kubelet, worker1.com Created container tomcat-container
Normal Started 104s kubelet, worker1.com Started container tomcat-container
Warning Unhealthy 10s (x4 over 40s) kubelet, worker1.com Readiness probe failed: Get http://localhost:8080/temp/index.html: dial tcp [::1]:8080: connect: connection refused
当我执行到容器中并执行 curl 命令时,没有就绪探测,我看到了响应。
apiVersion: apps/v1
kind: Deployment
metadata:
name: tomcat-deployment
spec:
replicas: 1
selector:
matchLabels:
app: tomcat
template:
metadata:
labels:
app: tomcat
role: rolling-update
spec:
volumes:
- name: shared-volume
emptyDir: {}
initContainers:
- name: busybox
image: busybox
volumeMounts:
- name: shared-volume
mountPath: /app-data/temp
command: ["/bin/sh"]
args: ["-c","echo '<h1>hellow from k8s!</h1>' > /app-data/temp/index.html"]
containers:
- name: tomcat-container
image: tomcat:9.0
# command: ["/bin/bash"]
# args: ["-c","mkdir -p /usr/local/tomcat/webapps/temp; touch index.html"]
volumeMounts:
- name: shared-volume
mountPath: /usr/local/tomcat/webapps/temp
ports:
- containerPort: 8080
readinessProbe:
initialDelaySeconds: 60
httpGet:
host: localhost
path: /temp/index.html
port: 8080
# exec:
# command:
# - curl
# - http://localhost:8080/temp/index.html
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 2
maxUnavailable: 1
---
kind: Service
apiVersion: v1
metadata:
name: tomcat-service
spec:
selector:
app: tomcat
type: NodePort
ports:
- protocol: TCP
port: 8080
targetPort: 8080
nodePort: 30080
readinessProbe
exec: 命令有效,pod 已成功启动。
问题: 任何输入为什么 httpGet 就绪在这种情况下不起作用。
来自容器的日志:
27-Jun-2020 22:41:17.709 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
27-Jun-2020 22:41:17.710 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat
27-Jun-2020 22:41:17.710 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat
27-Jun-2020 22:41:17.711 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat/temp
27-Jun-2020 22:41:17.711 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded Apache Tomcat Native library [1.2.24] using APR version [1.6.5].
27-Jun-2020 22:41:17.711 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
27-Jun-2020 22:41:17.712 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
27-Jun-2020 22:41:17.747 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.1.1d 10 Sep 2019]
27-Jun-2020 22:41:23.913 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
27-Jun-2020 22:41:24.324 INFO [main] org.apache.catalina.startup.Catalina.load Server initialization in [9,608] milliseconds
27-Jun-2020 22:41:25.112 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
27-Jun-2020 22:41:25.119 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/9.0.36]
27-Jun-2020 22:41:25.194 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/temp]
27-Jun-2020 22:41:27.980 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/temp] has finished in [2,766] ms
27-Jun-2020 22:41:28.100 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
27-Jun-2020 22:41:28.286 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [3,960] milliseconds
最佳答案
Exec 之所以有效,是因为它是在 localhost:8080 可用的容器中执行的。 但是 httpGet 是由 Kubelet 执行的。 因此,当主机指定为 localhost 时,它会尝试连接到节点上的端口 8080。因此失败。
请删除探测中的“host: localhost”,以便它默认为 pod ip 并按预期工作。
关于tomcat - kubernetes redinessProbe httpGet on tomcat 图像报告连接被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62615675/