Note To Self: How To Stop A Running Pod On Kubernetes.
3 Min Read
The Story
OMG, I just ran a Kubernetes command from the wild and now I cannot seem to stop or delete the running pod (that was me when my CPU fan sounded like an industrial fan).
So, this is what happened right. I have a RKE Kubernetes cluster running on a Vagrant box and I thought to myself. Why not try to use it to mine a few cryptos while at it; since the crypto business has been booming recently.
So the idea was to test it on my Vagrant box, and somehow let it find its way to run it elsewhere so that I can mine while I sleep and then one day wake up as a Gajillionare or something close.
Note To Self: Never blindly run commands on your system especially from the wild.
TL;DR
# Set a new size for a Deployment, ReplicaSet, Replication Controller, or StatefulSet.
kubectl scale --help
The How
Running a basic kubectl run
command to bring up a few mining pods where kube_config_cluster.yml
is my RKE config file.
#start monero_cpu_moneropool
kubectl run --kubeconfig kube_config_cluster.yml moneropool --image=servethehome/monero_cpu_moneropool:latest --replicas=1
#start minergate
kubectl run --kubeconfig kube_config_cluster.yml minergate --image=servethehome/monero_cpu_minergate:latest --replicas=1
#start cryptotonight
kubectl run --kubeconfig kube_config_cluster.yml minergate --image=servethehome/universal_cryptonight:latest --replicas=1
After realising that my CPU was choking, I then tried to stop the mining pods.
Little did I know that Kubernetes doesn’t support the stop/pause of the current state of the pod(s). Then I started deleting the pods thinking that this will automagically stop and delete the pods and sure enough that didn’t work.
That’s when it hinted to me, the command I copied ensures that there’s always 1 replica running, which was why the pods kept on being re-spawned.
The Walk-through
I managed to stop all my mining pods by ensuring that there are no working deployments which is simply done by setting the number of replicas to 0. Duh!!!
kubectl --kubeconfig=kube_config_cluster.yml scale --replicas=0 deployment minergate moneropool
kubectl --kubeconfig=kube_config_cluster.yml scale --replicas=0 replicaset minergate-686c565775 moneropool-69fbc5b6d5
Checking all running pods again, I can see that my mining pods have been paused/stopped.
And that’s how I failed to become a Gajillionare, maybe I should just run this in a production environment bwagagagaga!