In the previous blog, we discussed building deployment-ready Helm charts by creating common Kubernetes resources such as Deployment
, Ingress
, ConfigMap
, Secrets
, and Service
. We also explored customizing Helm chart templates and creating reusable helpers to make charts production-ready.
In this blog, we will dive into:
- Packaging and sharing Helm charts.
- CI/CD integration with ArgoCD.
- Best practices for storing and managing Helm charts.
- Deploying Helm charts using ArgoCD by creating an application definition.
Packaging and Sharing Helm Charts
After creating a Helm chart, the next step is to package and distribute it. Helm provides a simple way to package charts into a .tgz
archive for easy sharing and deployment.
Packaging a Helm Chart
Run the following command to package your Helm chart:
helm package myapp
This will generate a file like myapp-1.0.0.tgz, depending on the version specified in your Chart.yaml.
Storing Helm Charts
Once packaged, Helm charts can be stored in various locations for easy access and deployment. Here are the most common options:
1. OCI (Open Container Initiative) Registry
OCI registries like AWS Elastic Container Registry (ECR) or Docker Hub allow you to store Helm charts in a container-like repository.
Example: Storing a Helm Chart in AWS ECR
aws ecr get-login-password --region us-west-2 | \
helm registry login --username AWS --password-stdin 123456789012.dkr.ecr.us-west-2.amazonaws.com
helm push my-chart-1.0.0.tgz oci://123456789012.dkr.ecr.us-west-2.amazonaws.com/
2. Chart Repositories
Tools like ChartMuseum or public Helm repositories such as Artifact Hub provide an easy way to host and share Helm charts.
3. Git Repositories
Storing charts in Git alongside your application code allows for:
- Version control: Track changes and manage different versions of your Helm charts effectively.
- Easy collaboration and updates: Team members can contribute and review changes seamlessly.
- Integration with CI/CD pipelines: Automate the deployment and update process using CI/CD tools.
4. Self-Hosted Solutions
You can host your Helm charts on a web server or object storage (e.g., AWS S3) by generating an index.yaml
file. Use the following command to create the index file:
helm repo index /path/to/helm-charts --url https://example.com/charts/
Upload the charts and the index.yaml
file to your hosting service, and your repository is ready for use!
CI/CD Integration with ArgoCD
Overview of ArgoCD
ArgoCD is a declarative GitOps tool for Kubernetes. It continuously monitors the state of a Git repository and applies the defined manifests to your cluster. It also supports Helm charts directly, making it a powerful tool for managing Kubernetes applications.
Automating Helm Chart Deployment with ArgoCD
To deploy a Helm chart using ArgoCD, follow these steps:
1. Prepare Your Helm Chart
Ensure your chart is packaged and stored in a repository accessible to ArgoCD, such as AWS ECR.
2. Create an Application in ArgoCD
Define the Helm chart deployment in a Kubernetes manifest file. Here's an example:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: helm-app
namespace: argocd
spec:
ignoreDifferences:
- kind: "ConfigMap"
jsonPointers:
- /data
- kind: "Secret"
jsonPointers:
- /data
project: default
sources:
- chart: my-chart
repoURL: oci://123456789012.dkr.ecr.us-west-2.amazonaws.com
targetRevision: 1.0.0
helm:
valueFiles:
- $value/values/us/helm-app.yaml
releaseName: my-chart
- repoURL: 'https://github.com/<github_username>/repository'
targetRevision: prod
ref: value
destination:
server: "https://kubernetes.default.svc"
namespace: ivms-helm-app-prod
syncPolicy:
automated:
prune: true
selfHeal: true
allowEmpty: true
syncOptions:
- CreateNamespace=true
- PrunePropagationPolicy=background
- PruneLast=true
- ApplyOutOfSyncOnly=true
3. Apply the Application Manifest
Deploy the application manifest to the ArgoCD namespace:
kubectl apply -f application.yaml -n argocd
4. Monitor the Deployment
Use the ArgoCD UI or CLI to monitor the application sync status and logs.
NOTE : Your repositories(both github and helm repo) should be connected to ArgoCD.
Helm Chart Installation Using ArgoCD
ArgoCD makes it simple to install and manage Helm charts by automating the entire deployment process. With the above example, you have defined:
- Chart Source: The Helm chart stored in AWS ECR.
- Values File: Custom configuration for the deployment.
- Sync Policy: Automated synchronization with options for pruning, self-healing, and creating namespaces.
Wrapping Up
By packaging and sharing your Helm chart, and integrating it with ArgoCD for automated deployments, you achieve:
- Consistency: Helm charts ensure consistency across environments.
- Automation: ArgoCD automates deployments, reducing manual intervention.
- Scalability: ArgoCD scales well with multiple applications and clusters.
In the next blog, we will explore advanced Kubernetes topics, such handling secrets securely and writing cron jobs for refreshing aws sts tokens.
Top comments (0)