How to delete replication controller and its pods in kubernetes?

11/27/2019

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?

-- Bhanuprakash D
kubernetes
minikube

2 Answers

11/27/2019

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

-- iliefa
Source: StackOverflow

11/27/2019

below command is just enough

kubectl delete rc hello-rc

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

-- P Ekambaram
Source: StackOverflow