问题描述
我有一个 Kubernetes 问题,我需要在部署后将 2 个 jar(每个 jar > 1Mb)复制到一个 pod 中。所以理想的解决方案是我们不能使用 configMap (> 1Mb) 但我们需要在“initcontainer”中使用“wget”并下载 jars。 所以下面是我修改过的 kubernetes-template 配置。原始版本可在 https://github.com/dremio/dremio-cloud-tools/blob/master/charts/dremio/templates/dremio-executor.yaml
获得{{ if not .Values.DremioAdmin }}
apiVersion: apps/v1
kind: StatefulSet
Metadata:
name: dremio-executor
spec:
serviceName: "dremio-cluster-pod"
replicas: {{.Values.executor.count}}
podManagementPolicy: "Parallel"
revisionHistoryLimit: 1
selector:
matchLabels:
app: dremio-executor
template:
Metadata:
labels:
app: dremio-executor
role: dremio-cluster-pod
annotations:
dremio-configmap/checksum: {{ (.Files.Glob "config/*").AsConfig | sha256sum }}
spec:
terminationGracePeriodSeconds: 5
{{- if .Values.nodeselector }}
nodeselector:
{{- range $key,$value := .Values.nodeselector }}
{{ $key }}: {{ $value }}
{{- end }}
{{- end }}
containers:
- name: dremio-executor
image: {{.Values.image}}:{{.Values.imageTag}}
imagePullPolicy: IfNotPresent
securityContext:
runAsUser: 0
resources:
requests:
memory: {{.Values.executor.memory}}M
cpu: {{.Values.executor.cpu}}
volumeMounts:
- name: dremio-executor-volume
mountPath: /opt/dremio/data
##################### START added this section #####################
- name: dremio-connector
mountPath: /opt/dremio/jars
#################### END added this section ##########################
- name: dremio-config
mountPath: /opt/dremio/conf
env:
- name: DREMIO_MAX_HEAP_MEMORY_SIZE_MB
value: "{{ template "HeapMemory" .Values.executor.memory }}"
- name: DREMIO_MAX_DIRECT_MEMORY_SIZE_MB
value: "{{ template "DirectMemory" .Values.executor.memory }}"
- name: DREMIO_JAVA_EXTRA_OPTS
value: >-
-Dzookeeper=zk-hs:2181
-Dservices.coordinator.enabled=false
{{- if .Values.extraStartParams }}
{{ .Values.extraStartParams }}
{{- end }}
command: ["/opt/dremio/bin/dremio"]
args:
- "start-fg"
ports:
- containerPort: 45678
name: server
initContainers:
################ START added this section ######################
- name: installjars
image: {{.Values.image}}:{{.Values.imageTag}}
imagePullPolicy: IfNotPresent
securityContext:
runAsUser: 0
volumeMounts:
- name: dremio-connector
mountPath: /opt/dremio/jars
command: ["/bin/sh","-c"]
args: ["wget --no-check-certificate -O /dir/connector.jar https://<some nexus repo URL>/connector.jar; sleep 10;"]
################ END added this section ###############
- name: wait-for-zk
image: busyBox
command: ["sh","-c","until ping -c 1 -W 1 zk-hs > /dev/null; do echo waiting for zookeeper host; sleep 2; done;"]
# since we're mounting a separate volume,reset permission to
# dremio uid/gid
- name: chown-data-directory
image: {{.Values.image}}:{{.Values.imageTag}}
imagePullPolicy: IfNotPresent
securityContext:
runAsUser: 0
volumeMounts:
- name: dremio-executor-volume
mountPath: /opt/dremio/data
command: ["chown"]
args:
- "dremio:dremio"
- "/opt/dremio/data"
volumes:
- name: dremio-config
configMap:
name: dremio-config
{{- if .Values.imagePullSecrets }}
imagePullSecrets:
- name: {{ .Values.imagePullSecrets }}
{{- end}}
#################### START added this section ########################
- name: dremio-connector
emptyDir: {}
#################### END added this section ########################
volumeClaimTemplates:
- Metadata:
name: dremio-executor-volume
spec:
accessModes: [ "ReadWriteOnce" ]
{{- if .Values.storageClass }}
storageClassName: {{ .Values.storageClass }}
{{- end }}
resources:
requests:
storage: {{.Values.executor.volumeSize}}
{{ end }}
所以上面的方法不起作用,一旦我“执行”到 pod 中,我就看不到任何 jars 正在下载。我不明白上面有什么问题。但是请注意,如果我运行相同的 wget 命令,它会在 pod 内下载令我困惑的 jar。所以 URL 是有效的,目录的读写没有问题,但仍然没有下载 jar ???
解决方法
如果您可以完全消除对 Wget 的需求,那将使生活更轻松...
选项 1
如果可以的话,使用你自己的 docker 镜像会省去一些麻烦
Dockerfile
# docker build -f Dockerfile -t ghcr.io/yourOrg/projectId/dockerImageName:0.0.1 .
# docker push ghcr.io/yourOrg/projectId/dockerImageName:0.0.1
FROM nginx:1.19.10-alpine
# Use local copies of config
COPY files/some1.jar /dir/
COPY files/some2.jar /dir/
文件将在容器中准备好,不需要在 pod 定义中使用毫无意义的神秘命令。或者,如果您需要下载文件,您可以将执行该工作的脚本复制到 Docker 映像中,并在启动时通过 docker 指令 CMD 运行该脚本。
选项 2
或者,您可以进行两阶段部署...
- 创建持久卷
- 将卷挂载到一个 pod(使用 busybox 作为基础?),该 pod 将运行足够的时间以便文件从本地机器复制(或者如果您继续使用 Wget,则可以下载它们)
-
kubectl cp
(保留的)PersistentVolume 所需的文件 - 现在将 PV 挂载到 pod 的容器中,以便在 pod 启动时可以随时使用这些文件。
你的方法似乎是对的。 另一种解决方案可能是将 jar 包含在 Docker 映像中,但我认为这是不可能的,对吗?
您可以只使用 emptyDir
而不是 VolumeClaim
。
最后一个,我会在等待 ZooKeeper 获得一些时间之前下载 jar。