KB: How to generate kubernetes Kind templates

Instead of memorizing all the Kubernetes configuration yaml Kind templates you may use the imperative commands to generate them.  To generate Kubernetes KIND templates simply use the Imperative wtih dry-run.  Depending on the command the dry-run can either be applied on the client side or on the server (api) side.  

"Imperative commands are great for learning and interactive experiments, but they don't give you full access to the Kubernetes API. They're more commonly used to create YAML manifests and objects on the go. Declarative commands are useful for reproducible deployments and production."

Here is an example of how to generate pod kind, YAML configuration file.

  • kubectl run nginx --image=nginx:latest -o yaml --dry-run=client

Here is an example of how to generate a service kind, YAML configuration file.

  • kubectl create service clusterip my-svc --clusterip="None" -o yaml --dry-run=client


When working with declarative commands, you'll need a YAML manifest. However, if you use imperative commands, you can generate these files without actually creating the objects. For example, if you use the `—dry-run=client -o yaml" flag with an imperative command like kubectl, you'll get a YAML version of the operation (like above examples) that you're trying to do without actually applying the changes on the cluster. This can save you time and effort that would be spent writing YAML files from scratch. Plus, by storing the generated manifests in code repositories, you can use them declaratively as needed

Save the output from above examples to a yaml file and apply using the declarative command:
  • kubectl apply -f <file.yaml>



References:

https://kubernetes.io/docs/tasks/manage-kubernetes-objects/imperative-command/

https://www.squadcast.com/blog/introduction-to-kubernetes-imperative-commands#:~:text=Imperative%20and%20Declarative%20methods,-There%20are%20two&text=Imperative%20commands%20are%20great%20for,for%20reproducible%20deployments%20and%20production.


Comments

Popular posts from this blog

KB: Azure ACA Container fails to start (no User Assigned or Delegated Managed Identity found for specified ClientId)

Electron Process Execution Failure with FSLogix

KB:RMM VS DEX (Remote Monitoring Management vs Digital Employee Experience)