<p>I have the following code:</p>
<pre><code>config.load_incluster_config()
v1 = client.CoreV1Api()
my_init_containers = v1.read_namespaced_pod(namespace=NAMESPACE, name=pod_name).spec.init_containers
</code></pre>
<p>This gives me all the containers in <code>init_containers</code>. My problem is that I want to get only specific container: <code>git-sync-init-container</code>.</p>
<p>I can do:</p>
<pre><code>init = v1.read_namespaced_pod( namespace=NAMESPACE, name=pod_name).spec.init_containers[2]
</code></pre>
<p>But I don't want to use indexes. How can I get a container by name?
I tried to iterate over <code>my_init_containers</code> searching for <code>name=git-sync-init-container</code> but this is a <code>V1Container</code> type and it doesn't let me iterate over it.</p>

<p>You are close:</p>
<pre class="lang-py prettyprint-override"><code>my_init_containers = v1.read_namespaced_pod(namespace=NAMESPACE, name=pod_name).spec.init_containers
for container in my_init_containers:
    if container.name == &quot;the_one_im_looking_for&quot;:
        init = container
        break
</code></pre>
