Kubernetes Imperative vs Declarative
Contents
Two ways to manage Objects in Kubernetes
Imperative
Manage with Commands
You need to aware current state always.
You need to aware current state always.
Declarative
Manage with Files
Imperative
Commands
Create Objects
|
|
Update Objects
|
|
Commands with YAML
|
|
Declarative
Commands
kubectl apply
apply
is figuring out the objects exist automatically.
|
|
Common Command Options
–dry-run
--dry-run
--dry-run
is for testing your command.--dry-run=client
is to execute the command without create objects.-o yaml
-o yaml
-o yaml
will output the resource definition in YAML format on the screen.Example Commands
POD
|
|
Deployment
|
|
Service
|
|
Note
Both the above commands have their own challenges. While one of it cannot accept a
selector the other cannot accept a node port. I would recommend going with the
kubectl expose
command. If you need to
specify a node port, generate a definition file using the same command and manually input the nodeport before creating
the service.