[Kubernetes] Kubernetes Management Techniques
Kubernetes Management Techniques
- YAML Generators in kubectl commands
- Imperative vs Desclarative
- Three Management Approaches
YAML Generators in kubectl commands
kubectl create
use helper templates calledgenerators
- Generators can have different defaults by version
- Every resource in k8s has a specification(
spec
)
# see the deployment templates with --dry-run=client -o yaml
kubectl create deployment test --image nginx --dry-run=client -o yaml
# see the job templates with --dry-run=client -o yaml
kubectl create job test --image nginx --dry-run=client -o yaml
# see the service templates with --dry-run=client -o yaml
kubectl create deployment test --image nginx # deployment needed to expose
kubectl expose deploy test --port 80 --dry-run=client -o yaml
Imperative vs Desclarative
Imperative
: Focuses on how a program operates- For example, boil water, get 42 gram of medium-fine grounds, and poor over 700 grams of water, etc
- In k8s, the command lines (
kubectl run | create | update | etc.
) are imperative
Desclarative
: Focuses on what a program should accomplish- For example, “Barista i’d like a cup of coffee”
- In k8s, yaml find can be used(
kubectl apply -f values.yaml
)
Three Management Approaches
- Imperative commands:
kubectl run | expose | scale | edit | create deployment | etc.
- Best for dev/learning/personal projects
- Easy to learn, hardest to manage
- Imperative objects:
create | replace -f values.yaml
, etc.- Good for prod of small environments, single file per command
- Store changes in git-based yaml files
- Declarative:
apply -f values.yaml | dir/ | diff
- Best for prod, easier to automate
- Harder to understand and predict changes
-
Do not mix the approaches in production!