k8s-terraform

  • List the contents of the terraform files

image

  • Initialize terraform on the directory to doenload required providers

terraform init

image

  • Validate the terraform file using :

terraform plan

image

image

  • Apply the terraform configuraton file

terraform apply --auto-approve

image

image

  • Copy the output of the terraform configuration to the ~/.kube/config

  • Installing aws-iam-authenticator This enables using AWS IAM credentials to authenticate to a Kubernetes cluster

curl -Lo aws-iam-authenticator https://github.com/kubernetes-sigs/aws-iam-authenticator/releases/download/v0.5.9/aws-iam-authenticator_0.5.9_linux_amd64
chmod +x ./aws-iam-authenticator
mkdir -p $HOME/bin && cp ./aws-iam-authenticator $HOME/bin/aws-iam-authenticator && export PATH=$PATH:$HOME/bin
echo 'export PATH=$PATH:$HOME/bin' >> ~/.bashrc
  • Communicate with Kuberbetes cluster using kubectl get all

image

  • Get the pods in the cluster using 'kubectl get pods --all-namespaces'

image

  • Deploy the manifest for the pods deployment

kubectl apply -f manifests/deployment.yaml

image

  • Validate the deployment using kubectl get pods

image

  • Testing the deployment using the port forward

kubectl port-forward hello-kubernetes-6bf86759db-7jf7j 8080:8080

image

  • ALB Ingress Controller can be installed with Helm
  • Install Helm package
$ curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
$ chmod 700 get_helm.sh
$ ./get_helm.sh

image

  • Install the collection of YAML files necessary to run the ALB Ingress Controller. Add the following repository

helm repo add incubator https://charts.helm.sh/incubator

  • Install the ALB Ingress Controller in my cluster
helm install ingress incubator/aws-alb-ingress-controller \
  --set autoDiscoverAwsRegion=true \
  --set autoDiscoverAwsVpcID=true \
  --set clusterName=terraform-eks

image

  • Deploy the service loadbalancer on the cluster kubectl apply -f manifest/loadbalancer.yaml

image

image

  • Deploy the ingress.yaml for the service
wget https://raw.githubusercontent.com/kubernetes-sigs/aws-alb-ingress-controller/v1.1.9/docs/examples/alb-ingress-controller.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/aws-alb-ingress-controller/v1.1.9/docs/examples/rbac-role.yaml

the cluster name and vpc id is change in the alb-ingress-controller.yaml

image

image

image