<p>Can anyone help with this, please?</p>
<p>I have a mongo pod assigned with its service. I need to execute some commands while starting the container in the pod.</p>
<p>I found a small examples like this:</p>
<pre><code>command: [&quot;printenv&quot;]
    args: [&quot;HOSTNAME&quot;, &quot;KUBERNETES_PORT&quot;]
</code></pre>
<p>But I want to execute these commands while starting the pod:</p>
<pre><code>use ParkInDB
db.roles.insertMany( [ {name :&quot;ROLE_USER&quot;}, {name:&quot;ROLE_MODERATOR&quot;}, {name:&quot;ROLE_ADMIN&quot;} ])
</code></pre>

benhsouna chaima
<p>you need to choice one solution :</p>
<p>1- use <em><strong>init-container</strong></em> to deployment for change and execute some command or file</p>
<p>2- use command and args in deployment yaml</p>
<p>for init-container visit this <a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/#init-containers-in-use" rel="nofollow noreferrer">page</a> and use.</p>
<p>for comnad and args use this model in your deployment yaml file:</p>
<pre><code>- image:
  name:
  command: [&quot;/bin/sh&quot;]
  args: [&quot;-c&quot; , &quot;PUT_YOUR_COMMAND_HERE&quot;]
</code></pre>
