Voiced by Amazon Polly |
Overview
In today’s cloud environments, GitOps has become the preferred method for managing cloud resources, offering a declarative approach where Git acts as the central source of truth. This article will guide you through managing AWS resources directly from a Kubernetes cluster using KubeVela’s Terraform Controller alongside Terraform.
Git Repo: https://github.com/abhi-188/flux-tf-k8s
Pioneers in Cloud Consulting & Migration Services
- Reduced infrastructural costs
- Accelerated application deployment
Prerequisites
- An operational Kubernetes cluster
- The kubectl command-line tool installed and configured to communicate with your cluster.
- The Helm CLI (version 3 or newer) installed.
- Flux deployed and running in your Kubernetes cluster.
- Terraform installed and ready to use on your system.
- Access to a Git repository where you’ll store your configuration files.
- AWS credentials are available for authentication and are ideally stored as a Kubernetes secret for security.
Make sure you have all these components in place before proceeding.
Installing Flux
Flux is an open-source tool that allows you to synchronize Kubernetes resources directly from a Git repository and apply Terraform configurations. It can be installed either with Helm or with Kubectl applied.
- Installation with Helm (recommended): This method allows easy management of updates and configurations via Helm.
1 2 3 |
helm repo add fluxcd https://charts.fluxcd.io helm repo update helm install flux fluxcd/flux --namespace flux-system --create-namespace |
2. Installation with kubectl apply (alternative method): If Helm isn’t available or shouldn’t be used, you can also install Flux directly with kubectl apply:
1 |
kubectl apply -f https://github.com/fluxcd/flux2/releases/latest/download/install.yaml |
3. Status of Flux: After installation, check the status of Flux:
1 |
kubectl get pods -n flux-system |
Installing KubeVela Terraform Controller
The KubeVela Terraform Controller is a modern replacement for the now-archived Rancher Terraform Controller, allowing you to run Terraform directly within Kubernetes to manage AWS resources. To install the controller, use Helm:
1 2 |
helm repo add kubevela-addons https://charts.kubevela.net/addons helm upgrade --install terraform-controller -n terraform --create-namespace kubevela-addons/terraform-controller |
Storing AWS credentials as a K8s secret
To securely manage authentication, save your AWS credentials as a secret within your Kubernetes cluster:
1 2 3 4 |
kubectl create secret generic aws-secret \ --from-literal=AWS_ACCESS_KEY_ID=<your-access-key> \ --from-literal=AWS_SECRET_ACCESS_KEY=<your-secret-key> \ -n terraform |
Enabling Automatic Application of Terraform Configuration Changes
To guarantee that updates to your Terraform configuration are applied automatically, perform these checks before and after making changes.
- Check the Current Configuration: Before making any modifications, review the existing instance configuration:
1 |
aws ec2 describe-instances --query "Reservations[*].Instances[*].InstanceType" --output table |
Expected output:
1 2 3 4 5 |
------------------ | InstanceType | ------------------ | t3.nano | ------------------ |
- Change the Instance Type in Terraform: Update the instance type in terraform/ec2.yaml from t3.nano to t3.micro in your Git repository. Once you’ve made the change, stage, commit, and push your update with a clear message.
- Save the change in terraform/ec2.yaml.
- Stage the modified file:
1 |
git add terraform/ec2.yaml |
- Commit the update with a descriptive message:
1 |
git commit -m "Update EC2 instance type from t3.nano to t3.micro" |
- Push your commit to the remote repository:
1 |
git push origin <branch-name> |
3. After-Check in AWS: After Flux and Terraform have applied the change, check the instance configuration again:
1 |
aws ec2 describe-instances --query "Reservations[*].Instances[*].InstanceType" --output table |
Expected output:
1 2 3 4 5 |
------------------ | InstanceType | ------------------ | t3.micro | ------------------ |
Conclusion
By leveraging Flux and the KubeVela Terraform Controller, you can provision and manage AWS resources directly from your Kubernetes cluster.
When compared to traditional CI/CD-based deployments, adopting a GitOps workflow with Terraform delivers several key benefits:
- Automated synchronization: Any changes made in your Git repository are instantly picked up and applied without manually invoking a pipeline.
- Centralized source of truth: Infrastructure definitions are maintained declaratively in Git, streamlining version control, rollbacks, and audit trails.
- Enhanced consistency: GitOps guarantees that your infrastructure’s actual state always aligns with the intended configuration.
Drop a query if you have any questions regarding KubeVela and we will get back to you quickly.
Making IT Networks Enterprise-ready – Cloud Management Services
- Accelerated cloud migration
- End-to-end view of the cloud environment
About CloudThat
CloudThat is an award-winning company and the first in India to offer cloud training and consulting services worldwide. As a Microsoft Solutions Partner, AWS Advanced Tier Training Partner, and Google Cloud Platform Partner, CloudThat has empowered over 850,000 professionals through 600+ cloud certifications winning global recognition for its training excellence including 20 MCT Trainers in Microsoft’s Global Top 100 and an impressive 12 awards in the last 8 years. CloudThat specializes in Cloud Migration, Data Platforms, DevOps, IoT, and cutting-edge technologies like Gen AI & AI/ML. It has delivered over 500 consulting projects for 250+ organizations in 30+ countries as it continues to empower professionals and enterprises to thrive in the digital-first world.
FAQs
1. What is GitOps, and why is it useful for managing cloud infrastructure?
ANS: – GitOps is an operational model where Git repositories serve as the single source of truth for declarative infrastructure and application configurations. It ensures consistency, traceability, and automation by applying changes through Git workflows.
2. Why use the KubeVela Terraform Controller within Kubernetes?
ANS: – It allows you to run Terraform natively inside Kubernetes, enabling seamless management of cloud resources like AWS directly from your cluster and integrating Terraform with a GitOps workflow.
3. How does Flux detect changes and apply them automatically?
ANS: – Flux continuously monitors your Git repository for any changes in declarative configuration files and triggers reconciliation in the Kubernetes cluster to apply those changes automatically.

WRITTEN BY Abhishek Dubey
Abhishek works as a DevOps Engineer with over 2.5 years of hands-on experience in automating workflows, optimizing deployment pipelines, and enhancing system performance. Proficient in CI/CD tools, cloud services, and infrastructure as code, with a strong focus on improving operational efficiency and reliability. Adept at collaborating with cross-functional teams to drive continuous integration and delivery practices in fast-paced environments. He has excellent technical skills in Python, AWS, Jenkins, Docker, Kubernetes, Terraform, Helm Charts, GitOps(Argo CD), and Azure.
Comments