gpt4 book ai didi

kubernetes - 按名称查找 pod 时未知主机,通过 pod 重启解决

转载 作者:行者123 更新时间:2023-12-02 12:19:54 36 4
gpt4 key购买 nike

我有一个安装程序,可以在我的 CI 流中启动两个 pod,我们称它们为 web 和 activemq。当 web pod 启动时,它会尝试使用 k8s 分配的 amq-deployment-0.activemq pod 名称与 activemq pod 通信。

当尝试访问 amq-deployment1.activemq 时,网络会随机出现未知主机异常。如果我在这种情况下重新启动 web pod,则 web pod 与 activemq pod 的通信将没有问题。

发生这种情况时,我已经登录到 Web pod,并且/etc/resolv.conf 和/etc/hosts 文件看起来很好。主机/etc/resolve.conf 和/etc/hosts 很稀疏,没有任何问题。

信息:
只有 1 个工作节点。

kubectl --版本
Kubernetes v1.8.3+icp+ee

关于如何调试此问题的任何想法。我想不出它随机发生的充分理由,也想不出在 pod 重启时自行解决。

如果需要其他有用的信息,我可以得到它。预先感谢

对于activeMQ,我们确实有这个服务文件

apiVersion: v1 kind: Service
metadata:
name: activemq
labels:
app: myapp
env: dev
spec:
ports:
- port: 8161
protocol: TCP
targetPort: 8161
name: http
- port: 61616
protocol: TCP
targetPort: 61616
name: amq
selector:
component: analytics-amq
app: myapp
environment: dev
type: fa-core
clusterIP: None

还有这个 ActiveMQ 有状态集(这是模板)
kind: StatefulSet
apiVersion: apps/v1beta1
metadata:
name: pa-amq-deployment
spec:
replicas: {{ activemqs }}
updateStrategy:
type: RollingUpdate
serviceName: "activemq"
template:
metadata:
labels:
component: analytics-amq
app: myapp
environment: dev
type: fa-core
spec:
containers:
- name: pa-amq
image: default/myco/activemq:latest
imagePullPolicy: Always
resources:
limits:
cpu: 150m
memory: 1Gi
livenessProbe:
exec:
command:
- /etc/init.d/activemq
- status
initialDelaySeconds: 10
periodSeconds: 15
failureThreshold: 16
ports:
- containerPort: 8161
protocol: TCP
name: http
- containerPort: 61616
protocol: TCP
name: amq
envFrom:
- configMapRef:
name: pa-activemq-conf-all
- secretRef:
name: pa-activemq-secret
volumeMounts:
- name: timezone
mountPath: /etc/localtime
volumes:
- name: timezone
hostPath:
path: /usr/share/zoneinfo/UTC

Web 有状态集:
apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: pa-web-deployment
spec:
replicas: 1
updateStrategy:
type: RollingUpdate
serviceName: "pa-web"
template:
metadata:
labels:
component: analytics-web
app: myapp
environment: dev
type: fa-core
spec:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: component
operator: In
values:
- analytics-web
topologyKey: kubernetes.io/hostname
containers:
- name: pa-web
image: default/myco/web:latest
imagePullPolicy: Always
resources:
limits:
cpu: 1
memory: 2Gi
readinessProbe:
httpGet:
path: /versions
port: 8080
initialDelaySeconds: 30
periodSeconds: 15
failureThreshold: 76
livenessProbe:
httpGet:
path: /versions
port: 8080
initialDelaySeconds: 30
periodSeconds: 15
failureThreshold: 80
securityContext:
privileged: true
ports:
- containerPort: 8080
name: http
protocol: TCP
envFrom:
- configMapRef:
name: pa-web-conf-all
- secretRef:
name: pa-web-secret
volumeMounts:
- name: shared-volume
mountPath: /MySharedPath
- name: timezone
mountPath: /etc/localtime
volumes:
- nfs:
server: 10.100.10.23
path: /MySharedPath
name: shared-volume
- name: timezone
hostPath:
path: /usr/share/zoneinfo/UTC

这个 web pod 在查找我们配置的外部数据库时也有类似的“未知主机”问题。通过重新启动 pod 类似地解决了该问题。这是该外部服务的配置。也许从这个角度解决问题更容易? ActiveMQ使用数据库服务名查找DB并启动没有问题。
apiVersion: v1
kind: Service
metadata:
name: dbhost
labels:
app: myapp
env: dev
spec:
type: ExternalName
externalName: mydb.host.com

最佳答案

是否有可能是哪个 pod 及其容器中的应用程序先启动,然后再启动的问题?

在任何情况下,使用 Service 进行连接并且不建议使用 pod 名称,因为 Kubernetes 分配的 pod 名称在 pod 重新启动之间会发生变化。

测试连通性的一种方法是使用 telnet (或 curl 对于它支持的协议(protocol)),如果在图像中找到:

telnet <host/pod/Service> <port>

关于kubernetes - 按名称查找 pod 时未知主机,通过 pod 重启解决,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52228218/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com