Search code examples
kubectl

Why imperative pod creation doesn't have 'kubectl create'?


You can create service, deployment etc using kubectl create but you can't with a pod. You need to use kubectl run instead. What may be the reason for this? You technical create pod with kubectl run --generator=run-pod/v1 anyway isn't it?


Solution

  • I can only hypothesise that this was kind of an arbitrary decision, not a technical one.

    As of kubectl 1.16, kubectl create can create the following types of resources:

    clusterrole, clusterrolebinding, configmap, cronjob, deployment, job,
    namespace, poddisruptionbudget, priorityclass, quota, role, rolebinding,
    secret, service, serviceaccount
    

    As you can see, these are all resource types that are typically used in a standalone way. For example, it's common to directly create a Deployment or a Job. However, it's not common to directly create a Pod for running workloads, and it is not recommended (there are exceptions but they are mainly for debugging and management tasks). Instead, Pods should only be created as part of a Deployment, Job, etc.

    Given that, and that the imperative kubectl commands were initially designed for beginners, the kubectl team may have decided to not include Pods in kubectl create. Also, they just needed to draw the line somewhere, i.e., you can only include the most common resource types in kubectl create, otherwise the list would become really long.

    The way to run a single Pod is kubectl run --generator=run-pod/v1.