Reputation: 3712
I executed below command:
kubectl proxy --port=8081 &
kubectl proxy --port=8082 &
and of course I have 2 accessible endpoints:
curl http://localhost:8081/api/
curl http://localhost:8082/api/
But in the same time two running processes serving the same content. How to stop one of these processes in "kubectl" manner? Of course, I can kill the process but it seems to be a less elegant way...
Upvotes: 31
Views: 37031
Reputation: 641
In Windows, to stop the background job in Powershell, it is:
get-job
Stop-Job Job1
Upvotes: 1
Reputation: 16803
Try this, using your port #s of course
$ pkill -f 'kubectl proxy --port=8080'
Upvotes: 2
Reputation: 1103
Depending on the platform you could wrap the proxy in service / daemon, but seems like overkill I would just add aliases or functions to start and source them in your terminal/shell profile to make it easier.
or
kubectl-proxy-start() {
kubectl proxy &
}
kubectl-proxy-kill() {
pkill -9 -f "kubectl proxy"
}
Upvotes: 7
Reputation: 4616
The following works for me in the MacOS
pkill -9 -f "kubectl proxy"
Upvotes: 4
Reputation: 1016
ps -ef | grep "kubectl proxy"
will show you the PID of the process
Then you can stop it with
kill -9 <pid>
Upvotes: 11
Reputation: 121
Filter (grep) all "kube" pids and kill with loop:
for pid in `netstat -tulp | grep kube | awk '{print $7}' | awk -F"/" '{print $1}'| uniq`
do
kill -9 $pid
done
Upvotes: 2
Reputation: 316
Run this command to figure out the process id (pid):
netstat -tulp | grep kubectl
Then run sudo kill -9 <pid>
to kill the process.
Upvotes: 17
Reputation: 27160
I believe the "kubectl way" is to not background the proxy at all as it is intended to be a short running process to access the API on your local machine without further authentication.
There is no way to stop it other than kill or ^C (if not in background).
You can use standard shell tricks though, so executing fg
then ^C will work or kill %1
Upvotes: 25