Kubectl run - doesn't create replicaset

8/28/2020

I am using below command to create my pod

kubectl run pingpong --image alpine ping 1.1.1.1

This command works good, but doesn't create replicaset.

How can I create a replicaset with this command too? I tried below

kubectl create deployment pingpong --image alpine ping 1.1.1.1 

but it doesn't work.

-- gufi33
kubernetes

2 Answers

8/28/2020

From kubernetes version 1.18 kubectl run does not create deployment anymore because all the generators were deprecated.

You should use below command to create a deployment which internally creates a replicaset.

kubectl create deployment pingpong --image=alpine

Please note you can not pass a command like ping 1.1.1.1 in the above command.

If you want to add a command you need to edit the deployment created above using kubectl edit deployment pingpongor use a yaml to create it in first place.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: alpine-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: alpine
  template:
    metadata:
      labels:
        app: alpine
    spec:
      containers:
      - name: alpine
        image: alpline
        command: ["<Your command here>"]
-- Arghya Sadhu
Source: StackOverflow

8/28/2020

Well if you are on the kubernetes version above 1.18 then the first command only create pod.

So if you want to create pod,deployment and replicaset

use this command

 kubectl create deployment pingpong --image=alpine

and to list above created command objects use kubectl get pod,rs,deploy

-- Dashrath Mundkar
Source: StackOverflow