【发布时间】:2021-10-13 23:43:39
【问题描述】:
我正在使用 Kubenetes kubectl Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.2" 我有一个在 python pod + nginx pod 上运行的网站。
由于某种原因,如果我重新加载站点,我可以看到它发送到 pod 3 请求而不是 1,为什么会发生这种情况?
我将 env 从 docker-compose 转换为 kub ,在我的 docker-compose 中我没有这个问题。
nginx-service.yaml:
apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: /snap/kompose/19/kompose-linux-amd64 convert --volumes hostPath
kompose.version: 1.21.0 (992df58d8)
creationTimestamp: null
labels:
io.kompose.service: nginx
name: nginx
spec:
ports:
- name: "8443"
port: 8443
targetPort: 80
externalIPs:
- 10.10.10.13
selector:
io.kompose.service: nginx
status:
loadBalancer: {}
api 服务在 5001 端口上看起来是一样的
我可以在 nginx 和 api pod 中看到相同的请求记录 2-3X 次。
日志:
1628596046 [10], INF, Authentication ('Got New authentication request:', 'USER', 'ADMIN22')
1628596046 [10], INF, Authentication ('Got New authentication request:', 'USER', 'ADMIN22')
1628596046 [10], INF, Authentication ('Got New authentication request:', 'USER', 'ADMIN22')
1628596046 [10], INF, activeSessions ('Checking for active sessions...',)
1628596046 [10], INF, activeSessions ('Checking for active sessions...',)
1628596046 [10], INF, activeSessions ('Checking for active sessions...',)
1628596046 [10], INF, activeSessions ({},)
1628596046 [10], INF, activeSessions ({},)
1628596046 [10], INF, activeSessions ({},)
10.244.0.220 - - [10/Aug/2021 11:47:26] "GET /Authentication?token=9FB4FB18BCB182938263179252956219A4FAE2256D78D5E17E654CED9C6FB6BF HTTP/1.1" 200 -
10.244.0.220 - - [10/Aug/2021 11:47:26] "GET /Authentication?token=9FB4FB18BCB182938263179252956219A4FAE2256D78D5E17E654CED9C6FB6BF HTTP/1.1" 200 -
10.244.0.220 - - [10/Aug/2021 11:47:26] "GET /Authentication?token=9FB4FB18BCB182938263179252956219A4FAE2256D78D5E17E654CED9C6FB6BF HTTP/1.1" 200 -
有什么想法吗? 谢谢
================================= API 服务和 pod YAML:
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
kompose.cmd: /snap/kompose/19/kompose-linux-amd64 convert --volumes hostPath
kompose.version: 1.21.0 (992df58d8)
creationTimestamp: null
labels:
io.kompose.service: api
name: api
spec:
replicas: 1
selector:
matchLabels:
io.kompose.service: api
strategy:
type: Recreate
template:
spec:
hostNetwork: true
metadata:
annotations:
kompose.cmd: /snap/kompose/19/kompose-linux-amd64 convert --volumes host Path
kompose.version: 1.21.0 (992df58d8)
creationTimestamp: null
labels:
io.kompose.service: api
spec:
containers:
- image: 127.0.0.1:5000/api:latest
imagePullPolicy: "Never"
name: api
ports:
- containerPort: 5001
resources: {}
volumeMounts:
- mountPath: /api
name: api-hostpath0
restartPolicy: Always
serviceAccountName: ""
volumes:
- hostPath:
path: /root/api
name: api-hostpath0
status: {}
apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: /snap/kompose/19/kompose-linux-amd64 convert --volumes hostPath
kompose.version: 1.21.0 (992df58d8)
creationTimestamp: null
labels:
io.kompose.service: api
name: api
spec:
ports:
- name: "5001"
port: 5001
targetPort: 5001
externalIPs:
- 10.10.10.130
selector:
io.kompose.service: api
status:
loadBalancer: {}
【问题讨论】:
-
您能否提供一些有关从 Docker Compose 过渡到 Kubernetes 的详细信息?
-
我刚刚使用 Kompose 将文件从 docker yaml 转换为 kub yaml,并启动了 pod,到目前为止我遇到的唯一问题是 yaml 相关但我解决了所有问题,我只是不明白为什么当我的站点重新加载我可以在 api 和 nginx @JakubSiemaszko 的日志中看到 3 个请求
标签: kubernetes kubectl