CREATE KUBERNETES CLUSTER BY USING YAML FILE
abhya@abhyas-MacBook-Pro ~ % aws configure
abhya@abhyas-MacBook-Pro ~ % cd desktop
abhya@abhyas-MacBook-Pro ~ % mkdir eks_class_code
abhya@abhyas-MacBook-Pro desktop % cd eks_class_code
abhya@abhyas-MacBook-Pro eks_class_code % touch cluster.yml
abhya@abhyas-MacBook-Pro eks_class_code % open -t cluster.yml
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: abhyacluster
region: ap-south-1
nodeGroups:
— name: ng-1
instanceType: t2.micro
desiredCapacity: 2
— name: ng-2
instanceType: t2.small
desiredCapacity: 1
ssh:
publicKeyName: mykey1111
abhya@abhyas-MacBook-Pro ~ % cd desktop
abhya@abhyas-MacBook-Pro desktop % cd eks_class_code
abhya@abhyas-MacBook-Pro eks_class_code % open -t cluster.yml
abhya@abhyas-MacBook-Pro eks_class_code % eksctl create cluster -f cluster.yml
abhya@abhyas-MacBook-Pro eks_class_code % eksctl get cluster
NAME REGION
abhyacluster ap-south-1
abhya@abhyas-MacBook-Pro eks_class_code % aws eks update-kubeconfig — name abhyacluster
Updated context arn:aws:eks:ap-south-1:010574163167:cluster/abhyacluster in /Users/abhya/.kube/config
abhya@abhyas-MacBook-Pro eks_class_code % kubectl get pods
No resources found in default namespace.
abhya@abhyas-MacBook-Pro eks_class_code % kubectl get ns
NAME STATUS AGE
default Active 20m
kube-node-lease Active 20m
kube-public Active 20m
kube-system Active 20m
CLUSTER CREATED
Create a project integrating all the technologies that are being covered in EKS training.
It should includes the use if normal eks cluster and use them to launch various applications with the help of helm.
If you know terraform, then include that to setup the cluster.
Technology it can include,
EKS, EFS, Helm
Application could be a simple space server or jenkins workflow pipeline, or prometheus or grafana, etc
#creating k8s efs
provider “kubernetes” {
config_context_cluster = “arn:aws:eks:ap-south-1:010574163167:cluster/abhyacluster”
}
resource “kubernetes_namespace” “namespace” {
metadata {
name = “my-first-namespace”
}
}
resource “kubernetes_storage_class” “storageclass” {
metadata {
name = “ekssc”
}
storage_provisioner = “kubernetes.io/aws-ebs”
reclaim_policy = “Retain”
parameters = {
type = “io1”
}
}
#creating k8s pvc using storage class
resource “kubernetes_persistent_volume_claim” “clustervolume” {
metadata {
name = “eksvolume”
}
spec {
storage_class_name =”ekssc”
access_modes = [“ReadWriteOnce”]
resources {
requests = {
storage = “1Gi”
}
}
}
}
#creating k8s service load balancer
resource “kubernetes_service” “lb” {
metadata {
name = “ekslb”
}
spec {
selector = {
app = “webserver”
}
port {
port = 8080
target_port = 80
}
type = “LoadBalancer”
}
}
#creating k8s deployment for webapp using docker image
resource “kubernetes_deployment” “webdeployment” {
metadata {
name = “mywebpage”
labels = {
app = “myserver”
}
}
spec {
replicas = 1
selector {
match_labels = {
app = “myserver”
}
}
template {
metadata {
labels = {
app = “myserver”
}
}
spec {
container {
image = “vimal13/apache-webserver-php”
name = “mywebpage”
volume_mount {
mount_path = “/var/www/html/”
name = “eksvolume”
}
}
volume {
name =”eksvolume”
}
}
}
}
}
abhya@abhyas-MacBook-Pro terraform_eks % terraform init
abhya@abhyas-MacBook-Pro terraform_eks % terraform apply -auto-approve
service load balancer of aws used by k8s
USE HELM TO INSTALL PROMETHEUS AND GRAFANA
abhya@abhyas-MacBook-Pro eks_class_code % kubectl -n kube-system create serviceaccount tiller
abhya@abhyas-MacBook-Pro eks_class_code % kubectl create clusterrolebinding tiller — clusterrole cluster-admin — serviceaccount=kube-system:tiller
abhya@abhyas-MacBook-Pro eks_class_code % helm install — generate-name stable/prometheus — namespace prometheus — set alertmanager.persistentVolume.storageClass=”gp2" — set server.persistentVolume.storageClass=”gp2"
abhya@abhyas-MacBook-Pro eks_class_code % kubectl get svc -n prometheus
abhya@abhyas-MacBook-Pro eks_class_code % kubectl -n prometheus port-forward svc/prometheus-1594538640-server 8888:80
abhya@abhyas-MacBook-Pro eks_class_code % kubectl get all -n prometheus
abhya@abhyas-MacBook-Pro eks_class_code % kubectl create namespace grafana
abhya@abhyas-MacBook-Pro eks_class_code % helm install — generate-name stable/grafana — namespace grafana — set alertmanager.persistentVolume.storageClassName=”gp2"
abhya@abhyas-MacBook-Pro eks_class_code % kubectl get svc -n grafana
abhya@abhyas-MacBook-Pro eks_class_code % kubectl -n grafana port-forward svc/grafana-1594542481 8890:80