kubectl
in Reusable ScriptsIf you need stable output in a script, you should:
-o name
, -o json
, -o yaml
, -o go-template
, or -o jsonpath
--output-version
, since those output forms (other than -o name
) output the resource using a particular API version--generator
to pin to a specific behavior forever, if using generator-based commands (such as kubectl run
or kubectl expose
)kubectl run
In order for kubectl run
to satisfy infrastructure as code:
:v1234
, v1.2.3
, r03062016-1-4
, rather than :latest
(see Best Practices for Configuration for more information.)--record
, to annotate the created objects with the command line.kubectl run
flags, switch to configuration files checked into source control.kubectl run --generator=deployment/v1beta1
kubectl apply
kubectl apply
to update resources, always create resources initially with kubectl apply
or with --save-config
. See managing resources with kubectl apply for the reason behind it.