首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用于Helm3多荚部署的Init容器

用于Helm3多荚部署的Init容器
EN

Stack Overflow用户
提问于 2021-07-12 09:37:01
回答 1查看 496关注 0票数 0

我有一个头盔部署,部署2个集装箱吊舱。

现在我需要把init容器包括到一个集装箱舱中。

我是新掌舵的。请分享实现这一目标的片段。在这里,在规范中,我定义了两个容器,其中容器1依赖于容器2,因此容器2应该上升,然后我需要为容器1运行init容器。

deployment.yaml

代码语言:javascript
复制
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "test.fullname" . }}
  namespace: {{ .Values.global.namespace }}
  labels:
    {{- include "test.labels" . | nindent 4 }}
spec:
  {{- if not .Values.autoscaling.enabled }}
  replicas: {{ .Values.replicaCount }}
  {{- end }}
  selector:
    matchLabels:
      {{- include "testLabels" . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "test.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ .Values.cloudsqlproxySa }}
      automountServiceAccountToken: true
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      
      containers:
        - name: {{ .Chart.Name }} # For this I need to include the init container.
          securityContext:
            {{- toYaml .Values.test.securityContext | nindent 12 }}
          image: "{{ .Values.test.image.repository }}:{{ .Values.test.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.test.image.pullPolicy }}
          ports:
            - name: {{ .Values.test.port.name }}
              containerPort: {{ .Values.test.port.containerPort }}
              protocol: {{ .Values.test.port.protocol }}
          livenessProbe:
            httpGet:
              path: /
              port: {{ .Values.test.port.containerPort }}
          readinessProbe:
            httpGet:
              path: /
              port: {{ .Values.test.port.containerPort }}
          envFrom:
            - configMapRef:
                name: {{ .Values.configmap.name }}  
          resources:
            {{- toYaml .Values.test.resources | nindent 12 }}
          volumeMounts:
          - name: gcp-bigquery-credential-file
            mountPath: /secret
            readOnly: true
      
        - name: {{ .Chart.Name }}-gce-proxy 
          securityContext:
            {{- toYaml .Values.cloudsqlproxy.securityContext | nindent 12 }}
          image: "{{ .Values.cloudsqlproxy.image.repository }}:{{ .Values.cloudsqlproxy.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.cloudsqlproxy.image.pullPolicy }}
          command:
          - "/cloud_sql_proxy"
          - "-instances={{ .Values.cloudsqlConnection }}=tcp:{{ .Values.cloudsqlproxy.port.containerPort }}"
          ports:
          - name: {{ .Values.cloudsqlproxy.port.name }}
            containerPort: {{ .Values.cloudsqlproxy.port.containerPort }}
          resources:
            {{- toYaml .Values.cloudsqlproxy.resources | nindent 12 }}
          volumeMounts:
          - name: gcp-bigquery-credential-file
            mountPath: /secret
            readOnly: true    

      volumes:
      - name: gcp-bigquery-credential-file
        secret:
          secretName: {{ .Values.bigquerysecret.name }}

      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
EN

回答 1

Stack Overflow用户

发布于 2021-07-16 13:47:46

将此作为一个社区wiki发布出来,随时进行编辑和扩展。

正如@anemyte在评论中所述,启动主容器之后启动init容器是不可能的,这是init容器背后的逻辑。理解init-容器

@DavidMaze可能的解决方案是将容器分离到不同的部署中,并使用应用程序设置一个容器来重新启动自己,直到代理容器启动并运行为止。全文引用:

如果init容器在无法到达代理容器时退出,并且在单独的部署中运行代理容器,则可以在应用程序容器重新启动的位置设置一个设置,直到代理启动并运行为止。这意味着将其拆分为templates目录中的两个单独的文件。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68345081

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档