Playing with Running Pods

Learn different ways to interact with pods.

After we have a pod running, we can interact with it in a few different ways. Let’s see a few examples.

First, let’s run the pod from our previous example by using the following command:

kubectl apply -f nginx.yaml

To access the application locally, you need to run:

kubectl port-forward nginx 3001:80

Note: Please wait for the pods to be in a running state before executing the port-forward command.

But to access the application on this platform, you need to add an additional address flag. After running the port-forward command, in order to run further commands, we can open a new terminal, or we can run the port-forward command with nohup.

kubectl port-forward --address 0.0.0.0 nginx 3001:80

Note: nohup is a POSIX command which means no hang up. It will make sure that port-forward is running in the background like a service, and it will also enable us to further write commands in the same terminal without having to open a new one. The above command would now become:

nohup kubectl port-forward --address 0.0.0.0 nginx 3001:80 > /dev/null 2>&1 &

Get hands-on with 1400+ tech skills courses.