Search code examples
dockerkuberneteskubernetes-helm

Running script containing kubectl commands in helm installation


I have a shell script that has several kubectl commands, I need to execute it as a part of helm installation.

#!/bin/bash kubectl create secret generic mysecret --from-literal=username=$USER_NAME --from-literal=password=$passwrd

I have written a job which execute this script.

apiVersion: batch/v1
kind: Job
metadata:
  name: "sagdfghd"

spec:
  template:        
    spec:
      containers:
        - name: sagdfghd
          image: {{ .Values.jobs.dockerRegistry }}
          command: ["sh", "-c", {{ .Files.Get "scripts/myscript.sh" | quote }} ]

But as the script is running inside container it is not able to find kubectl command.

Any idea how can I run this script??

TIA


Solution

  • What image does {{ .Values.jobs.dockerRegistry }} resolve to and does it have the kubectl tool installed on it? It most likely does not have kubectl installed on it, so you will have to add the kubectl install instructions in your Dockerfile. Those instructions will depend on what your base Docker image is. See the following link:

    https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl