<p>I'm currently running through the secure deployment guide for CockroachDB on Kubernetes and while it works exactly as expected, but I'm searching for ways to streamline/automate the deployment.  I'm using <code>Configs</code> to deploy, and I would honestly just like to be able to automate the final step (after <code>kubectl create -f cockroachdb-statefulset.yaml</code>).  I've been searching around for guides on streamlining deployments, but I haven't come up with much.  Is there a way to complete the following after the config application:</p>

<pre><code>kubectl exec -it cockroachdb-0 \
-- /cockroach/cockroach init \
--certs-dir=/cockroach/cockroach-certs
</code></pre>

<p>Perhaps as part of an <code>initContainer</code> in the <code>cockroachdb-statefulset.yaml</code> config?</p>

<p>I'm also looking for a way to automate the creation of a db/user account, so any insight there would be greatly appreciated.</p>

<p>Thanks!</p>

<p>take a look on <a href="https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/" rel="nofollow noreferrer">kubernetes jos</a></p>

<pre><code>apiVersion: batch/v1
kind: Job
metadata:
  name: pi
spec:
  template:
    spec:
      containers:
      - name: pi
        image: perl
        command: ["perl",  "-Mbignum=bpi", "-wle", "print bpi(2000)"]
      restartPolicy: Never
  backoffLimit: 4
</code></pre>

<p>You can integrate this yaml within your deployment, but I do think you need write some wrapper script to confirm the cockroach service is up and health first. </p>

<p>so the job's command coule be:</p>

<pre><code>while true;
do
  if `command to check health`; then
    # run kubernetes exec
    exit
  else
    sleep 5
  fi
done
</code></pre>
