Why does kubectl create only support certain resources?

8/22/2019

I'm looking to create yaml files for specific resources (pvs, pvcs, policies and so on) via the command line with kubectl.

kubectl create only supports the creation of certain resource types (namely clusterroles, clusterrolebindings, configmaps, cronjobs, deployments, jobs, namespaces, pod disruption budgets, priorityclasses, quotas, roles, rolebindings, secrets, services and serviceaccounts).

Why doesn't it support pods, pvs, pvcs, etc?

I know of kubectl run --generator=run=pod/v1 for pods, but is there a specific reason it hasn't been added to kubectl create?

I searched the docs and github issues, but couldn't find an explanation.

I know of tools like ksonnet, but I was wondering if there is a native way (or a reason why there isn't).

-- char
kubectl
kubernetes

1 Answer

8/22/2019

You can create any type of object with kubectl create. To do that you have two solutions :

  1. Using a file descriptor : kubectl create -f my-pod-descriptor.yml
  2. Using stdin (where your file content is in fact in your console) :
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
  name: busybox-sleep
spec:
  containers:
  - name: busybox
    image: busybox
    args:
    - sleep
    - "1000000"
EOF

Now back to the question, as to why didn't they add a kubectl create pod command for example. I don't really have the answer.
My guess is because it is not really a good practice to manage pods directly. It is recommended to use deployments instead. And you have a kubectl create deployment command.

What about other objects wich are perfectly fine such as pv or pvc. Well, I don't know :)

Just keep in mind that it is not really a good practice to create/manage everything from the console, as you won't be able to keep the history of what you are doing. Prefer using files managed in a SCM.

Thus, I guess the K8S team is not putting too much an effort in a procedure or command that is not recommended. Which is fine to me.

-- Marc ABOUCHACRA
Source: StackOverflow