This content originally appeared on DEV Community and was authored by Prashant Lakhera
When managing Kubernetes deployments across multiple environments, such as development, staging, and production, keeping track of different configurations can become challenging. This is where Kustomize steps in to make your life easier. Unlike traditional methods that require you to modify original YAML files directly, Kustomize allows you to customize Kubernetes resource definitions without altering the base YAML files. It layers configurations on top of base resources, enabling you to manage multiple environments with a single set of YAML files.
Let's explore some of the essential Kustomize commands that you can use in your Kubernetes workflows:
Generate a Kustomization File
kustomize create --autodetect
This command generates a kustomization.yaml file by automatically detecting the Kubernetes resource files in the current directory. This file will define the resources, patches, and other customizations that Kustomize will manage.
Build Kubernetes Manifests
kustomize build .
This command builds the final Kubernetes manifests by applying the customizations defined in the kustomization.yaml file to the base resources. The output is a fully rendered set of YAML files that can be applied to your Kubernetes cluster.
Apply the Built Manifests to a Kubernetes Cluster
kubectl apply -k .
This command applies the customized resources directly to your Kubernetes cluster. The -k flag tells kubectl to use Kustomize to build the manifests before applying them.
Set a New Image in Your Kustomization
kustomize edit set image image_name=${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.$AWS_REGION.amazonaws.com/$ECR_REPOSITORY:$GITHUB_SHA
This command updates the kustomization.yaml file to set a new image for your Kubernetes deployment. The image name is set dynamically using environment variables or secrets provided in a CI/CD pipeline (e.g., GitHub Actions). Here, image_name is replaced with the Docker image hosted in AWS ECR, tagged with the commit SHA ($GITHUB_SHA) for traceability.
Conclusion
Kustomize is a powerful tool that brings flexibility and simplicity to managing Kubernetes configurations. By using Kustomize, you can efficiently handle multiple environments, reduce configuration complexity, and ensure that your Kubernetes resources are always in sync with your deployment needs.
đź“š If you enjoy these blog posts, please check out my three books on AWS, DevOps, and Machine Learning.
https://pratimuniyal.gumroad.com/l/BuildinganLLMOpsPipelineUsingHuggingFace
https://pratimuniyal.gumroad.com/l/cracking-the-devops-interview
https://www.amazon.com/AWS-System-Administrators-automate-infrastructure/dp/1800201532
This content originally appeared on DEV Community and was authored by Prashant Lakhera
Prashant Lakhera | Sciencx (2024-08-20T22:37:59+00:00) 🤖 End to End LLMOps Pipeline - Part 9 - Kustomize🤖. Retrieved from https://www.scien.cx/2024/08/20/%f0%9f%a4%96-end-to-end-llmops-pipeline-part-9-kustomize%f0%9f%a4%96/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.