【发布时间】:2020-05-31 15:00:39
【问题描述】:
我有一个包含一个 init 容器和一个应用程序容器的 pod, 它们之间有一个带有共享文件夹的卷。
我的问题是,init 容器每天运行一次甚至更多次,因此它会从卷中删除节点模块,然后由于缺少模块而导致主应用程序崩溃。 应用容器没有重启,只有 init 容器。
有人熟悉 k8s 中的这个问题吗?为什么这些重启只发生在 init 容器中?
谢谢:)
编辑: 部署 yaml 文件 -
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "25"
creationTimestamp: "2020-05-19T06:48:18Z"
generation: 25
labels:
apps: ******
commit: ******
name: *******
namespace: fleet
resourceVersion: "24059934"
selfLink: *******
uid: *******
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app: *******
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app: *******
commit: *******
revision: *******
spec:
containers:
image: XXXXXXXXXXXX
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 3
httpGet:
path: /ping
port: http
scheme: HTTP
initialDelaySeconds: 120
periodSeconds: 30
successThreshold: 1
timeoutSeconds: 30
name: *******
ports:
- containerPort: 1880
name: http
protocol: TCP
readinessProbe:
failureThreshold: 20
httpGet:
path: /ping
port: http
scheme: HTTP
initialDelaySeconds: 20
periodSeconds: 5
successThreshold: 1
timeoutSeconds: 30
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /opt/breeze
name: workdir
dnsPolicy: ClusterFirst
imagePullSecrets:
- name: flowregistrykey
initContainers:
image: XXXXXXXXXXXX
imagePullPolicy: IfNotPresent
name: get-flow-json
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /work-dir
name: workdir
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
volumes:
- emptyDir: {}
name: workdir
status:
availableReplicas: 1
conditions:
- lastTransitionTime: "2020-06-01T12:30:10Z"
lastUpdateTime: "2020-06-01T12:30:10Z"
message: Deployment has minimum availability.
reason: MinimumReplicasAvailable
status: "True"
type: Available
- lastTransitionTime: "2020-05-19T06:48:18Z"
lastUpdateTime: "2020-06-01T12:45:05Z"
message: ReplicaSet "collection-associator.sandbox.services.collection-8784dcb9d"
has successfully progressed.
reason: NewReplicaSetAvailable
status: "True"
type: Progressing
observedGeneration: 25
readyReplicas: 1
replicas: 1
updatedReplicas: 1
这张图片解释了问题- pod 是 7 天前创建的,但是里面的文件是今天创建的,并且没有 node_modules 文件夹 - 因为只有 init 容器再次运行,而不是 app 容器,所以没有 mpm install
【问题讨论】:
-
你可以通过设置
restartPolicy: Never来检查吗? -
这个设置不是只适用于整个 pod 吗?如果容器应用程序崩溃,我希望它能够恢复并再次运行。
-
initContainer 不应(重新)启动,除非(重新)创建 pod。也许您的 CI 运行并更新,例如,在我们重新创建 pod 中的 Deployment?
-
如果你愿意分享 yaml 会更容易。
-
我已经编辑并添加了更多解释
标签: kubernetes