首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >仅当我向部署中添加第二个常规容器时,才会引发初始化容器的部署抛出错误

仅当我向部署中添加第二个常规容器时,才会引发初始化容器的部署抛出错误
EN

Stack Overflow用户
提问于 2021-05-04 17:44:15
回答 1查看 121关注 0票数 0

您好,我目前正在尝试使用DB cloudsql实例在GKE中部署sonarqube 7.8-community。

这需要2个容器(一个用于sonarqube,另一个用于cloudproxy,以便连接到DB)

然而,Sonarqube容器也需要一个init容器来提供一些特殊的内存需求。

当我只使用sonarqube镜像和init容器创建部署时,它工作得很好,但这没有任何用处,因为我需要cloudsql代理容器来连接到我的外部数据库。但是,当我添加这个容器时,部署突然出现以下错误

代码语言:javascript
复制
deirdrerodgers@cloudshell:~ (meta-gear-306013)$ kubectl create -f initsonar.yaml
The Deployment "sonardeploy" is invalid:spec.template.spec.initContainers[0].volumeMounts[0].name: Not found: "init-sysctl"

这是我的完整的yaml文件,包含init容器和其他两个容器。我想知道问题是不是因为它不知道将init容器应用到哪个容器?

代码语言:javascript
复制
 apiVersion: apps/v1
 kind: Deployment
 metadata:
   labels:
     app: sonardeploy
   name: sonardeploy
   namespace: sonar
 spec:
   replicas: 1
   selector:
     matchLabels:
       app: sonardeploy
   strategy: {}
   template:
     metadata:
       labels:
         app: sonardeploy
     spec:
       initContainers:
         - name: init-sysctl
           image: busybox:1.32
           imagePullPolicy: IfNotPresent
           securityContext:
             privileged: true
           resources:
            {}
           command: ["sh",
                     "-e",
                     "/tmp/scripts/init_sysctl.sh"]
           volumeMounts:
             - name: init-sysctl
               mountPath: /tmp/scripts/
       volumes:
       - name: init-sysctl
         configMap:
           name: sonarqube-sonarqube-init-sysctl
           items:
             - key: init_sysctl.sh
               path: init_sysctl.sh
     spec:
       containers:
       - image: sonarqube:7.8-community
         name: sonarqube
         env:
           - name: SONARQUBE_JDBC_USERNAME
             valueFrom:
             secretKeyRef:
               name: sonarsecret
               key: username
           - name: SONARQUBE_JDBC_PASSWORD
             valueFrom:
             secretKeyRef:
               name: sonarsecret
               key: password
           - name: SONARQUBE_JDBC_URL
             value: jdbc:postgresql://localhost:5432/sonar
         ports:
           - containerPort: 9000
             name: sonarqube
       - name: cloudsql-proxy
         image: gcr.io/cloudsql-docker/gce-proxy:1.17
         command: ["/cloud_sql_proxy",
                   "-instances=meta-gear-306013:us-central1:sonardb=tcp:5432",
                   "-credential_file=/secrets/service_account.json"]
         securityContext:
           runAsNonRoot: true
         volumeMounts:
         - name: cloudsql-instance-credentials-volume
           mountPath: /secrets/
           readOnly: true
       volumes:
       - name: cloudsql-instance-credentials-volume
         secret:
           secretName: cloudsql-instance-credentials
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-05-05 15:54:42

您的yaml文件不正确。您有两个spec:块。它应该只有一个。您需要将它们组合在一起。在spec块下面应该是initContainers块,然后是containers,最后是volumes块。查看下面正确的yaml文件:

代码语言:javascript
复制
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: sonardeploy
  name: sonardeploy
  namespace: sonar
spec:
  replicas: 1
  selector:
    matchLabels:
      app: sonardeploy
  strategy: {}
  template:
    metadata:
      labels:
        app: sonardeploy
    spec:
      initContainers:
        - name: init-sysctl
          image: busybox:1.32
          imagePullPolicy: IfNotPresent
          securityContext:
            privileged: true
          resources:
           {}
          command: ["sh",
                    "-e",
                    "/tmp/scripts/init_sysctl.sh"]
          volumeMounts:
            - name: init-sysctl
              mountPath: /tmp/scripts/
      containers:
      - image: sonarqube:7.8-community
        name: sonarqube
        env:
          - name: SONARQUBE_JDBC_USERNAME
            valueFrom:
            secretKeyRef:
              name: sonarsecret
              key: username
          - name: SONARQUBE_JDBC_PASSWORD
            valueFrom:
            secretKeyRef:
              name: sonarsecret
              key: password
          - name: SONARQUBE_JDBC_URL
            value: jdbc:postgresql://localhost:5432/sonar
        ports:
          - containerPort: 9000
            name: sonarqube
      - name: cloudsql-proxy
        image: gcr.io/cloudsql-docker/gce-proxy:1.17
        command: ["/cloud_sql_proxy",
                  "-instances=meta-gear-306013:us-central1:sonardb=tcp:5432",
                  "-credential_file=/secrets/service_account.json"]
        securityContext:
          runAsNonRoot: true
        volumeMounts:
        - name: cloudsql-instance-credentials-volume
          mountPath: /secrets/
          readOnly: true
      volumes:
      - name: cloudsql-instance-credentials-volume
        secret:
          secretName: cloudsql-instance-credentials
      - name: init-sysctl
        configMap:
          name: sonarqube-sonarqube-init-sysctl
          items:
            - key: init_sysctl.sh
              path: init_sysctl.sh   
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67382354

复制
相关文章

相似问题

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