Kubectl port forward works from command line but silently fails from Ansible task

3/21/2020

I am learning to automate kubernetes cluster using Ansible

I am able to create the cluster and run kubectl apply -f service and kubectl apply -f deployment through ansible task and they work fine, but when I run kubectl port-forward service/simple-api 3000:3000 & in the output, it shows command executed successfully but when I check for running services on my target host, It didn't start. Although when I run the same command directly on the host terminal it works properly.

enter image description here

-- nitesh sharma
ansible
kubernetes

1 Answer

3/21/2020

You will need a nohup in front of that command in order for it to survive the ssh disconnect that happens at the end of the command: or shell: task

-- mdaniel
Source: StackOverflow