Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete replication controller and its pods in kubernetes?

What is the command to delete replication controller and its pods?

I am taking a course to learn k8s on pluralsight. I am trying to delete the pods that I have just created using Replication controller. Following is my YAML:

apiVersion: v1
kind: ReplicationController
metadata:
  name: hello-rc
spec:
  replicas: 2
  selector:
    app: hello-world
  template:
    metadata:
      labels:
        app: hello-world
    spec:
      containers:
      - name: hello-ctr
        image: nigelpoulton/pluralsight-docker-ci:latest
        ports:
        - containerPort: 8080

If I do 'kubectl get pods' following is the how it looks on my mac:

enter image description here

I have tried the following two commands to delete the pods that are created in the Minikube cluster on my mac, but they are not working:

kubectl delete pods hello-world kubectl delete pods hello-rc

Could someone help me understand what I am missing?

like image 633
bp4D Avatar asked Dec 11 '22 01:12

bp4D


2 Answers

you can delete the pods by deleting the replication controller that created them

kubectl delete rc hello-rc

also, because pods created are just managed by ReplicationController, you can delete only theReplicationController and leave the pods running

kubectl delete rc hello-rc --cascade=false

this means the pods are no longer managed .you can create a new ReplicationController with the proper label selector and manage them again

Also,instead of replicationcontrollers, you can use replica sets. They behave in a similar way, but they have more expressive pod selectors. For example, a ReplicationController can’t match pods with 2 labels

like image 66
iliefa Avatar answered Jan 04 '23 01:01

iliefa


below command is just enough

kubectl delete rc hello-rc

One more thing is that ReplicationController is deprecated rather ReplicaSets is preferred

like image 34
P Ekambaram Avatar answered Jan 04 '23 01:01

P Ekambaram