I want to kill a process

7/23/2019

I want to delete a process from process list pod_de.csv file

Content of pod_de.csv file

NAME                                READY   STATUS    RESTARTS   AGE
FebwinterMind-897654db-knbbj    2/2     Running   0          46h
DecNightmarch-897654db-n6qhk    2/2     Running   0          6d10h
DecNightmarch-897654db-v2rgt    0/2     Evicted   0          6d10h
DecNightmarch-897654db-5sswn    0/2     Evicted   0          6d10h
DecNightmarch-897654db-hqntn    2/2     Running   0          6d10h
DecNightmarch-897654db-z42r8    2/2     Running   0          35h
DecNightmarch-765897654db-qgbpb     2/2     Running   0          5d14h
AugNightmarch-774bbfc656-96bs6   2/2     Running   0          6d10h
AugNightmarch-774bbfc656-qnnkt   2/2     Running   0          6d10h
FebwinterMind-765897654db-gk5vw      2/2     Running   0          6d13h
FebwinterMind-765897654db-vhk8p      2/2     Running   0          6d13h
ogfileprocess-5h9ih8934b7b-dpbvt      2/2     Running   0          15h
nedesignprocess-765897654db-rshps     2/2     Running   0          6d10h
nedesignprocess-765897654db-rzqf7     0/2     Evicted   0          6d10h
nedesignprocess-765897654db-sbhps     2/2     Running   0          10h
referencedata-765897654db-xlc82      2/2     Running   0          6d11h
clientmyql-58b7d9b687-f9225   2/2     Running   0          5d18h
clientmyql-58b7d9b687-tfmrl   2/2     Running   0          5d18h

I want to kill "ogfileprocess-5h9ih8934b7b-dpbvt" process

I implemented this

#!/bin/bash
pods=$(kubectl get pods > pod_de.csv)
echo "$pods"
Running_OG_process=$(awk '/ogfileprocess/{print $1}' pod_de.csv)
echo "Running Process:" $Running_OG_process
kubectl delete pod $Running_OG_process

But I am getting additional \r\r\ and due to this it is not killing that particular process

Running Process: ogfileprocess-5h9ih8934b7b-dpbvt
Error from server (NotFound): pods "ogfileprocess-5h9ih8934b7b-dpbvt\r\r" not found

Actual value getting from file is

ogfileprocess-5h9ih8934b7b-dpbvt\r\r

I want

ogfileprocess-5h9ih8934b7b-dpbvt

So that I can kill the process.

Can Someone help me on this, or can we do this in another way. Full code will be highly appreciated

-- Chanty
bash
kubernetes
linux
shell

1 Answer

7/23/2019

You can just do this to delete pod with ogfileprocess in its name:

kubectl get pods | grep ogfileprocess | awk '{print $1}' | xargs kubectl delete pod
-- Vikram Hosakote
Source: StackOverflow