Welcome to the Linux Foundation Forum!

Create resources commands, apply -f vs create -f

Hello,

I can see on the labs from this LFS8 (ie. Labs from the 9 chapter) objects are often created from a yaml file using the command create -f instead of apply -f.

In the former LFS158, whenever an object was created from a yaml file, the command used was apply -f.

I know both commands lead to the same output, but I would like to know why on this course the use of create -fis favoured instead of apply -f.

One is an imperative appraoch (create) and while the other one is a declarative (apply), but both are used to create an object from a yaml file. So I do not understand what is the difference.

Thanks in advance for your time and answer.

Sincerely,

Josep Maria

Best Answer

  • chrispokorni
    chrispokorni Posts: 2,385
    Answer ✓

    Hi @josepmaria,

    Happy and prosperous new year!

    The create command is used imperatively to launch various objects such as deployments, services, secrets, configmaps, serviceaccounts, etc., per the kubectl CLI reference.

    The create command can also be used declaratively to launch objects defined through manifests (yaml or json).

    The apply declarative command, however, can be used to launch new objects from manifests, to apply updates to existing objects from manifests, and to combine multiple manifests together for kustomization purposes.

    Regards,
    -Chris

Answers

Categories

Upcoming Training