<p>Scenario is like this:</p>
<p>I have a pod running in a node in K8s cluster in GCP. cluster is created using kops and pod is created using kne_cli.</p>
<p>I know only the name of the pod e.g. &quot;test-pod&quot;.</p>
<p>My requirement is to configure something in the node where this pod is running. e.g. I want to update &quot;iptables -t nat&quot; table in node.</p>
<p>how to access the node and configure it from within a pod?</p>
<p>any suggestion will be helpful.</p>

Manomugdha
<p>You the Job or deployment or POD, not sure how POD is getting managed. If you just want to run that task Job is good fir for you.</p>
<p>One option is to use <strong>SSH</strong> way :</p>
<p>You can run one POD inside that you get a list of Nodes or specific node as per need and run SSH command to connect with that node.</p>
<p>That way you will be able to access Node from POD and run commands top of Node.</p>
<p>You can check this document for ref : <a href="https://alexei-led.github.io/post/k8s_node_shell/" rel="nofollow noreferrer">https://alexei-led.github.io/post/k8s_node_shell/</a></p>
<p>Option <strong>two</strong> :</p>
<p>You can <strong>mount</strong> <strong>sh</strong> file on <strong>Node</strong> with <strong>IP table command</strong> and invoke that shell script from POD to execute which will run the command whenever you want.</p>
<p><strong>Example</strong> :</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: command
data:
  command.sh: |
    #!/bin/bash
    echo &quot;running sh script on node..!&quot;
---
apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: command
spec:
  schedule: &quot;*/1 * * * *&quot;
  jobTemplate:
    spec:
      template:
        spec:
          serviceAccountName: cron-namespace-admin
          containers:
          - name: command
            image: IMAGE:v1
            imagePullPolicy: IfNotPresent
            volumeMounts:
            - name: commandfile
              mountPath: /test/command.sh
              subPath: command.sh
            - name: script-dir
              mountPath: /test
          restartPolicy: OnFailure
          volumes:
          - name: commandfile
            configMap:
              name: command
              defaultMode: 0777
          - name: script-dir
            hostPath:
              path: /var/log/data
              type: DirectoryOrCreate
</code></pre>
<p>Use <strong>privileged</strong> mode</p>
<pre><code>    securityContext:
      privileged: true
</code></pre>
<blockquote>
<p>Privileged - determines if any container in a pod can enable
privileged mode. By default a container is not allowed to access any
devices on the host, but a &quot;privileged&quot; container is given access to
all devices on the host. This allows the container nearly all the same
access as processes running on the host. This is useful for containers
that want to use linux capabilities like manipulating the network
stack and accessing devices.</p>
</blockquote>
<p>Read more : <a href="https://kubernetes.io/docs/concepts/security/pod-security-policy/#privileged" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/security/pod-security-policy/#privileged</a></p>
