Not sure how but I've got numerous pods running that seem to be due to multiple repliacasets for each deployment.
This occurred after I did some heavy editing of multiple deployments.
Is there some easy way of deleting orphaned replica sets? As opposed to manually inspecting each, and determining if it matches with a deployment, and then delete it?
To delete a ReplicaSet and all of its Pods, use kubectl delete . The Garbage collector automatically deletes all of the dependent Pods by default.
First, confirm the name of the node you want to remove using kubectl get nodes , and make sure that all of the pods on the node can be safely terminated without any special procedures. Next, use the kubectl drain command to evict all user pods from the node.
These artifacts include your ledger data in persistent storage and the keys that are stored in Kubernetes secrets. Log in to your console and go to the node overview page. Click Delete under the node name and enter the node name on the slider to permanently remove the node from the cluster.
you can edit your deployment and limit the history to 2 or 0
kubectl -n master edit deploy you_deployment
spec:
replicas: 2
revisionHistoryLimit: 2
revisionHistoryLimit
is an optional field that specifies the number of old ReplicaSets to retain to allow rollback
By default, 10 old ReplicaSets
will be kept, change it to one so you dont have more than one old replicaset.
Offical Link
Tested the field as below
Created NGINX deployment updated multiple times and generate few replicaset as listed below
$ kubectl get all
NAME READY STATUS RESTARTS AGE
pod/nginx-854998f596-6jtth 1/1 Running 0 18s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 9d
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/nginx 1/1 1 1 6m20s
NAME DESIRED CURRENT READY AGE
replicaset.apps/nginx-59d5958c9f 0 0 0 4m5s
replicaset.apps/nginx-669cf47c4f 0 0 0 94s
replicaset.apps/nginx-6ff549666b 0 0 0 2m21s
replicaset.apps/nginx-854998f596 1 1 1 2m7s
replicaset.apps/nginx-966c7f84 0 0 0 108s
Edit the running deployment and update revisionHistoryLimit field and set to zero as revisionHistoryLimit: 0
$ kubectl edit deployments.apps nginx
deployment.apps/nginx edited
Old Replica set are removed.
$ kubectl get all
NAME READY STATUS RESTARTS AGE
pod/nginx-854998f596-6jtth 1/1 Running 0 52s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 9d
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/nginx 1/1 1 1 6m54s
NAME DESIRED CURRENT READY AGE
replicaset.apps/nginx-854998f596 1 1 1 2m41s
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With