我正在嘗試通過 helm 圖表在 Openshift 上部署一個容器化的 webapp。當我部署應用程式時,我在 pod 日志中收到以下錯誤 -
Events:
Type Reason Age From Message
Normal Pulled 14m kubelet Successfully pulled image "<private-gitlab-registry-docker-image>:latest" in 3.787555091s
Warning Failed 14m kubelet Error: container create failed: time="2022-11-11T13:51:47Z" level=error msg="runc create failed: unable to start container process: exec: \"python3 src/myapp.py\": stat python3 src/myapp.py: no such file or directory"
這是碼頭檔案 -
FROM <private-gitlab-registry-centos-image>
ADD files/etc/yum.repos.d/* /etc/yum.repos.d/
RUN yum update -y
WORKDIR /app
RUN yum install -y python-keystoneclient python3-flask python3-keystoneauth1 python3-redis python3-werkzeug python3-pip python3-keystoneclient
RUN pip install flask-caching
COPY . /app
ENTRYPOINT [ "python3" ]
CMD [ "src/myapp.py" ]
當我手動嘗試運行這個 docker 鏡像時,它作業得很好。但是當我在 Kubernetes 上部署它時,kubelet 會拋出上述錯誤。
這是我的 deployment.yaml -
---
apiVersion: apps/v1
kind: Deployment # Type of Kubernetes resource
metadata:
name: myapp # Unique name of the Kubernetes resource
spec:
replicas: 1 # Number of pods to run at any given time
selector:
matchLabels:
app: myapp # This deployment applies to any Pods matching the specified label
template: # This deployment will create a set of pods using the configurations in this template
metadata:
labels: # The labels that will be applied to all of the pods in this deployment
app: myapp
spec:
containers:
- name: myapp
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
imagePullPolicy: {{ .Values.image.imagePullPolicy }}
{{- include "myapp.command" . | nindent 8 }}
resources:
requests:
cpu: 100m
memory: 100Mi
ports:
- containerPort: 8080 # Should match the port number that the Go application listens on
env: # Environment variables passed to the container
- name: REDIS_HOST
value: redis-master
- name: REDIS_PORT
value: "6379"
和 values.yaml -
image:
repository: gitlab-registry.cern.ch/batch-team/hepspec-query/hepspec-query
tag: latest
imagePullSecret: {}
imagePullPolicy: Always
command: [ "python3" , "src/hepspecapp.py" ]
args: {}
uj5u.com熱心網友回復:
在這里做的最簡單的事情是洗掉 Helm 圖表中提供的部分command:,并覆寫影像的ENTRYPOINT. 映像已經知道它應該運行什么命令(如果奇怪地拆分為兩個 Docker 指令),并且您在運行映像時不需要指定它。類似地,在部署時重新配置它以運行其他命令而不實質上重新架構容器設定是很奇怪的。
containers:
- name: myapp
image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
imagePullPolicy: {{ .Values.image.imagePullPolicy }}
# but you don't need to specify command: or make it configurable
如果使此可配置對您很重要,那么您可能會遇到默認 Go 序列化模板中串列的語法問題。如果你跑過helm template你的圖表,它可能會列印出類似的東西
containers:
- name: myapp
image: gitlab-registry.cern.ch/batch-team/hepspec-query/hepspec-query:latest
imagePullPolicy: Always
command: [python3 src/hepspecapp.py]
也就是說,.Values.command它是一個串列,它在內部被決議并存盤為一個串列,并且您得到的默認序列化不是values.yaml檔案中的內容。巧合的是,事實證明這是有效的 YAML,但現在它是一個包含單個字串的串列,其中包含一個嵌入的空格。
Helm 包含一個檔案較少的toYaml函式,可以將任意結構轉換回有效的 YAML。這是從第一列開始縮進的,因此您需要確保indent結果正確。
containers:
- name: myapp
{{- if .Values.command }}
command:
{{ .Values.command | toYaml | indent 6 }}
{{- end }}
{{- if .Values.args }}
args:
{{ .Values.args | toYaml | indent 6 }}
{{- end }}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/533198.html
