<p>After an unexpected power failure, the mongodb service I deployed on k8s could not be restarted normally. The log of mongodb showed that there was a problem with its data and could not be started.</p>
<p>I did not record the specific error log.</p>

Keys
<p>Here is my fix:</p>
<h2>First</h2>
<p>change k8s deployment.yaml config.</p>
<p>Because we want to repair the data file of mongodb, the first step is to make the mongo pod run, we run the command in the pod.</p>
<p>Now change the startup command of the container:</p>
<pre class="lang-yaml prettyprint-override"><code> containers:
      - name: mongodb
        image: mongo:latest
        command:  [&quot;sleep&quot;]
        args: [&quot;infinity&quot;]
        imagePullPolicy: IfNotPresent
        ports:
        # .......

</code></pre>
<p>After apply it.
If I guessed correctly, the mongo pod should be up and running.</p>
<h2>Second</h2>
<p>Use mongod command to repair data.</p>
<pre class="lang-bash prettyprint-override"><code>kubectl exec -it &lt;YOURPODNAME&gt; -- mongod --dbpath &lt;YOURDBPATH&gt; --repair --directoryperdb
</code></pre>
<p>I have to exec it with <code>--directoryperdb</code>, if you run it error, you can try remove it.</p>
<p>If I guessed correctly, So far everything is fine.</p>
<h2>Third</h2>
<p>Recover k8s deployment.yaml, back to the way they were.</p>
<p>Now reapply it.</p>
<p>---------- Manual split line</p>
<p>The above is my repair process. Its worked for me. I just record it. You can refer to it to fix your mongodb. Thank you.</p>
