kubectl CLI supports both imperative and declarative ways to create and manage Kubernetes objects like Pod, Deployment, Service, namespace etc.
Imperative
way:
In this
approach, we operate directly on live objects in a cluster using kubectl CLI as
arguments or flags.
It follows verb-driven commands to create or manage Kubernetes objects.
Syntax:
Example:
for more info visit @http://millionvisit.blogspot.com/2020/12/kubernetes-for-developers-3-kubectl-cli.html
Advantages:
- Commands
are simple, easy to learn and remember.
- Commands
require only a single step to make changes to the cluster.
Disadvantages
- Commands
cannot be committed to source control system and difficult to review.
- Commands
do not provide an audit trail associated with changes.
- Commands
do not provide a template for creating new objects.
Declarative
way:
In this approach, we create YAML or JSON files for creating, updating, or deleting Kubernetes objects in a cluster using kubectl CLI.
Syntax:
Example:
for more info visit @http://millionvisit.blogspot.com/2020/12/kubernetes-for-developers-3-kubectl-cli.html
Advantages:
- Object
configurations can be stored in a source control system for reviewing
changes before push.
- Object
configuration provides a template for creating new objects.
Disadvantages
- Object
configuration requires basic understanding of the object schema.
- Object
configuration requires the additional step of writing a YAML file.
Convert Imperative to Declarative way:
Option A:
- Export the
live object to a local object configuration file:
kubectl get {<kind>/<name>} --export -o yaml > {<kind>_<name>}.yaml
Ex:
Option B:
1. Export the live object to a local object configuration file:
kubectl get {<kind>/<name>} -o yaml > {<kind>_<name>}.yaml
> kubectl get deployments testnginx -o yaml > testnginx2.yaml
2. Remove the status field from the configuration file
3. use replace command to execute the file
kubectl replace -f <kind>_<name>.yaml
> kubectl replace -f testnginx2.yaml
- Kubernetes for Developers #25: PersistentVolume and PersistentVolumeClaim in-detail
- Kubernetes for Developers #24: Kubernetes Volume hostPath in-detail
- Kubernetes for Developers #23: Kubernetes Volume emptyDir in-detail
- Kubernetes for Developers #22: Access to Multiple Clusters or Namespaces using kubectl and kubeconfig
- Kubernetes for Developers #21: Kubernetes Namespace in-detail
- Kubernetes for Developers #20: Create Automated Tasks using Jobs and CronJobs
- Kubernetes for Developers #19: Manage app credentials using Kubernetes Secrets
- Kubernetes for Developers #18: Manage app settings using Kubernetes ConfigMap
- Kubernetes for Developers #17: Expose service using Kubernetes Ingress
- Kubernetes for Developers #16: Kubernetes Service Types - ClusterIP, NodePort, LoadBalancer and ExternalName
- Kubernetes for Developers #15: Kubernetes Service YAML manifest in-detail
- Kubernetes for Developers #14: Kubernetes Deployment YAML manifest in-detail
- Kubernetes for Developers #13: Effective way of using K8 Readiness Probe
- Kubernetes for Developers #12: Effective way of using K8 Liveness Probe
- Kubernetes for Developers #11: Pod Organization using Labels
- Kubernetes for Developers #10: Kubernetes Pod YAML manifest in-detail
- Kubernetes for Developers #9: Kubernetes Pod Lifecycle
- Kubernetes for Developers #8: Kubernetes Object Name, Labels, Selectors and Namespace
- Kubernetes for Developers #7: Imperative vs. Declarative Kubernetes Objects
- Kubernetes for Developers #6: Kubernetes Objects
- Kubernetes for Developers #5: Kubernetes Web UI Dashboard
- Kubernetes for Developers #4: Enable kubectl bash autocompletion
- Kubernetes for Developers #3: kubectl CLI
- Kubernetes for Developers #2: Kubernetes for Local Development
- Kubernetes for Developers #1: Kubernetes Architecture and Features
Happy Coding :)
No comments:
Post a Comment