Error from server (NotFound): deployments.extensions "1" not found(Error deleting a deployment in Kubernetes)

6/22/2019

I am getting this error when trying to delete the deployments using the command below, any ideas or suggestions on what could be the reason and how I can only limit to deleting the deployments that are actually running ?

kubectl delete deployments $(kubectl get deployments | awk 'match($6,/[0-9]+d/) {print $0}') 

Error from server (NotFound): deployments.extensions "1" not found

Error from server (NotFound): deployments.extensions "1d" not found

-- EaglesEye
containers
kubernetes

1 Answer

6/24/2019

I'm not sure, but maybe the number of columns in 'kubectl get deployment' command differs between different Kubernetes client version, so to avoid this behavior, it's better to format output with custom-columns option to have a fixed number of fields for more predictable behavior with 'awk' processing, e.g.

kubectl get deployment -o custom-columns=DEPLOYMENT:.metadata.name,READY_REPLICAS:.status.readyReplicas | awk '$2 ~ /[1-9]+/ {print $1}'
-- Nepomucen
Source: StackOverflow