how to apply multi-command in the yaml?

12/5/2018

I got this error message, but I don`t understand Why?

plz look at command:, argu:

Offical Document Link

error: error validating "jenkins.yaml": error validating data: [ValidationError(Deployment.spec.template.spec.initContainers[0].args[0]): invalid type for io.k8s.api.core.v1.Container.args: got "array", expected "string", ValidationError(Deployment.spec.template.spec.initContainers[0].command[0]): invalid type for io.k8s.api.core.v1.Container.command: got "array", expected "string"]; if you choose to ignore these errors, turn validation off with --validate=false

jenkins.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: jenkins
  labels:
    app: jenkins
spec:
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: jenkins
        tier: jenkins
    spec:
      serviceAccountName: jenkins
      initContainers:
      - image: lachlanevenson/k8s-kubectl:v1.11.2
        name: kubectl-config
        command:
        - ["/bin/sh", "-c"]
        args:
        - ["usermod -aG docker jenkins; /kubectl-config-context.sh"]
        volumeMounts:
        - name: kubeconfig
          mountPath: "/root/.kube"
        - name: kubectl-jenkins-context
          mountPath: "/kubectl-config-context.sh"
          subPath: "kubectl-config-context.sh"
      containers:
      - image: 127.0.0.1:30400/jenkins:latest
        name: jenkins
        securityContext:
          privileged: true
        volumeMounts:
        - name: kubeconfig
          mountPath: /var/jenkins_home/.kube
        - name: docker
          mountPath: /var/run/docker.sock
        - name: jenkins-persistent-storage
          mountPath: /var/jenkins_home
        ports:
        - containerPort: 8080
          name: jenkins
      volumes:
      - name: kubectl-jenkins-context
        configMap:
          name: kubectl-jenkins-context
          items:
          - key: kubectl-config-context.sh
            path: kubectl-config-context.sh
      - name: kubeconfig
        emptyDir: {}
      - name: docker
        hostPath:
          path: /var/run/docker.sock
      - name: jenkins-persistent-storage
        persistentVolumeClaim:
          claimName: jenkins-claim
-- seoultree
docker
jenkins
kubernetes

1 Answer

12/5/2018

I think that you are defining yaml array in a wrong way, command and args needs to be as follow:

command: ["/bin/sh", "-c"]
args: ["usermod", "-aG", "docker", "jenkins", ";", "/kubectl-config-context.sh"]
-- c4f4t0r
Source: StackOverflow