Install AWS CLI and Configure
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
sudo apt install unzip
unzip awscliv2.zip
sudo ./aws/install
Okay now after installing the AWS CLI, let's configure the AWS CLI so that it can
authenticate and communicate with the AWS environment.
aws configure
Install and Setup Kubectl
Moving forward now we need to set up the kubectl also onto the EC2 instance.
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s
https://storage.googleapis.com/kubernetes-
release/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin
kubectl version
Install and Setup eksctl
curl --silent --location
"https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -
s)_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/eksctl /usr/local/bin
eksctl version
Install Helm chart
$ 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
This way we install all AWS CLI, kubectl, eksctl and Helm.
Follow below steps to install terraform on AmazonLinux.
sudo yum install -y yum-utils shadow-utils
sudo yum-config-manager --add-repo
https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
sudo yum -y install terraform
Creating an Amazon EKS cluster using terraform
Code available in https://github.com/ksnithya/blue-green.git
git clone https://github.com/ksnithya/blue-green.git
cd blue-green
terraform init
terraform plan
terraform apply
aws eks --region ap-south-1 update-kubeconfig --name eks_cluster_demo
Installing the Kubernetes Metrics Server
kubectl apply -f https://github.com/kubernetes-sigs/metrics-
server/releases/latest/download/components.yaml
kubectl get deployment metrics-server -n kube-system
Install Prometheus
Now we install the Prometheus using the helm chart.
Add Prometheus helm chart repository
helm repo add prometheus-community https://prometheus-community.github.io/helm-
charts
Update the helm chart repository
helm repo update
helm repo list
Create prometheus namespace
kubectl create namespace Prometheus
Install Prometheus
helm install prometheus prometheus-community/kube-prometheus-stack -n prometheus
View the Prometheus dashboard by forwarding the deployment ports
kubectl port-forward statefulset.apps/prometheus-prometheus-kube-prometheus-
prometheus 9090 -n prometheus &
run curl localhost:9090/graph
Install Grafana
Add the Grafana helm chart repository. Later, Update the helm chart repository.
helm repo add grafana https://grafana.github.io/helm-charts
helm repo update
Create a namespace Grafana
kubectl create namespace Grafana
Install the Grafana
helm install grafana grafana/grafana \
--namespace grafana \
--set adminPassword='Venkat@123' \
--set service.type=LoadBalancer
We can change the service of Prometheus to LoadBalance.
kubectl get service/prometheus-kube-prometheus-prometheus -n prometheus -o
yaml>prometheus.yml
[ec2-user@ip-172-31-9-225 blue-green]$ cat prometheus.yml
apiVersion: v1
kind: Service
metadata:
annotations:
meta.helm.sh/release-name: prometheus
meta.helm.sh/release-namespace: prometheus
labels:
app: kube-prometheus-stack-prometheus
app.kubernetes.io/instance: prometheus
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/part-of: kube-prometheus-stack
app.kubernetes.io/version: 55.5.1
chart: kube-prometheus-stack-55.5.1
heritage: Helm
release: prometheus
self-monitor: "true"
name: prometheus-kube-prometheus-prometheus
namespace: prometheus
resourceVersion: "6646"
uid: 0e68febb-a677-49b9-86b6-85602ea04fcc
spec:
ports:
- name: http-web
port: 9090
protocol: TCP
targetPort: 9090
- appProtocol: http
name: reloader-web
port: 8080
protocol: TCP
targetPort: reloader-web
selector:
app.kubernetes.io/name: prometheus
operator.prometheus.io/name: prometheus-kube-prometheus-prometheus
sessionAffinity: None
type: LoadBalancer
status:
loadBalancer: {}
[ec2-user@ip-172-31-9-225 blue-green]$
kubectl replace -f prometheus.yml –force
above command will replace the service to LOadbalancer.
We can access the Graphana using Loadbalancer URL.
http:// ad49ef87dbee742d9a930b9cb301b163-206512672.ap-south-
1.elb.amazonaws.com:80
Now we can add our Prometheus to it.
Home -> connections -> Datasource - > Add
Give name and Prometheus service Loadbalancer URL.
Now we create dashboard.
Home -> dashboard -> New -> Import( we use existing Grafana dashboard)
“6417” dashboard of Kubernetes.
Give name, Select the Prometheus we have created. Then import it.