aws eks --region us-west-2 update-kubeconfig --name tf-helm-spot
Let verify that we can see our pods
kubectl get pods -A
should look something like this
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system aws-node-rk5lp 2/2 Running 0 151m
kube-system coredns-558f647b89-9dbsh 1/1 Running 0 117m
kube-system coredns-558f647b89-sld2s 1/1 Running 0 117m
kube-system kube-proxy-qpfpm 1/1 Running 0 151m
Managing Helm charts with Terraform streamlines the process of deploying applications to your Kubernetes cluster on AWS EKS. It brings infrastructure-as-code principles to Kubernetes application management, making it easier to maintain and version-control your deployments.
For updates or removal of Helm releases, you can modify your Terraform configuration and reapply. This approach ensures consistency and repeatability in your Kubernetes deployments.
Lets give it a go. Add this to our main.tf file.
## Using Helm provider moduel helm_release to launch Spot controller
resource "helm_release" "helm-spotinst-kubernetes-cluster-controller" {
name = "helm-spotinst-kubernetes-cluster-controller"
depends_on = [module.eks]
repository = "https://spotinst.github.io/spotinst-kubernetes-helm-charts"
chart = "spotinst-kubernetes-cluster-controller"
version = "1.0.116"
set {
name = "spotinst.token"
value = var.spotinst_token
}
set {
name = "spotinst.account"
value = var.spotinst_account
}
set {
name = "spotinst.clusterIdentifier"
value = var.cluster_identifier
}
}
Save the main.tf file and run this command again.
terraform apply
hint: terraform apply -auto-approve
Verify Spot controller installation
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system aws-node-rk5lp 2/2 Running 0 151m
kube-system coredns-558f647b89-9dbsh 1/1 Running 0 117m
kube-system kube-proxy-qpfpm 1/1 Running 0 151m
kube-system spotinst-kubernetes-cluster-controller-555d68849d-stdc8 1/1 Running 0 152m
Congratulations you’ve installed a spot controller by using Terraform and Helm. Lets try another example
add the next code block to your main.tf file. We will lauch a cool k8s tool called kubeview.
# Installing Kubeview, found at https://artifacthub.io/packages/helm/kubeview/kubeview
resource "helm_release" "kubeview" {
name = "kubeview-art"
repository = "https://benc-uk.github.io/kubeview/charts"
chart = "kubeview"
version = "0.1.31"
set {
name = "ingress.enabled"
value = "true"
}
}
Save the file and run this again,
terraform apply
Verify the installation by running
kubectl get pods -A
NAMESPACE NAME READY STATUS RESTARTS AGE
default kubeview-art-86876846f5-9tjfr 1/1 Running 0 152m
kube-system aws-node-rk5lp 2/2 Running 0 151m
kube-system coredns-558f647b89-9dbsh 1/1 Running 0 117m
kube-system coredns-558f647b89-sld2s 1/1 Running 0 117m
kube-system kube-proxy-qpfpm 1/1 Running 0 151m
kube-system spotinst-kubernetes-cluster-controller-555d68849d-stdc8 1/1 Running 0 152m
Now lets access it and see what it is.
Please open a new terminal session and keep it running separetly, run this that new session.
kubectl port-forward service/kubeview-art 8080:80
you should see this output
Forwarding from 127.0.0.1:8080 -> 8080
Forwarding from [::1]:8080 -> 8080
Lets access it and see, its pretty cool. Open you browser and go to localhost:8080 or 127.0.0.1:8080
- Access at http://localhost:8080
Click on top to change the namespace to see different views.
here is a short demo Kubeview demo