Skip to content

Latest commit

 

History

History
161 lines (120 loc) · 4.41 KB

readme.md

File metadata and controls

161 lines (120 loc) · 4.41 KB

AWS EKS

Useful commands:

  • watch kubectl get pods,services,deployments --all-namespaces -o wide
  • kubectl rollout restart deployment NAME_DEPLOYMENT -n NAMESPACE
  • kubectl get events --field-selector involvedObject.name=POD_NAME -n NAMESPACE
EXERCISE 1: Create EKS cluster
You decide to create an EKS cluster - the managed Kubernetes Service of AWS. To simplify the whole creation and configurations, you use eksctl.With eksctl you create an EKS cluster with 3 Nodes and 1 Fargate profile

Solution:

1. Install eksctl

brew tap weaveworks/tap
brew install weaveworks/tap/eksctl

2. Create Clsuter

Create yaml file and use aws EKS CLI

# Create YAML (cluster.yaml)

apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

metadata:
  name: jane-cluster
  region: eu-west-3

nodeGroups:
  - name: my-node-group
    desiredCapacity: 3
    instanceType: t2.micro

fargateProfiles:
  - name: my-fargate-profile
    selectors:
      - namespace: my-app

# Create Cluster
eksctl create cluster -f cluster.yaml

OR only use EKS CLI Commands

# create cluster with 3 EC2 instances and store access configuration to cluster in kubeconfig.jane-cluster.yaml file 
eksctl create cluster --name=jane-cluster --nodes=3 --kubeconfig=./kubeconfig.jane-cluster.yaml

# create fargate profile in the cluster. It will apply for all K8s components in my-app namespace
eksctl create fargateprofile --cluster jane-cluster --name my-fargate-profile --namespace my-app

3. Configure kubectl to connect to the cluster

# Check region (needs to be the same as in our cluster)
aws config list

# Create kubeconfig file (with information on how to connect to our cluster)
aws eks --region <your-region> update-kubeconfig --name <your-cluster-name>
aws eks update-kubeconfig --name jane-cluster

# Validate:
cat /Users/jfoerster008/.kube/config

4. Validate that cluster got created

kubectl get node
eksctl get fargateprofile --cluster jane-cluster

Deletion of cluster:

eksctl delete cluster --name jane-cluster

EXERCISE 2: Deploy Mysql and phpmyadmin
You deploy mysql and phpmyadmin on EC2 nodes with the same setup as before.

Solution:

1. Point kubectl to your cluster

export KUBECONFIG=/Users/jfoerster008/.kube/config

2. Use Helm Charts to create 3 SQL Instances

helm repo add bitnami https://charts.bitnami.com/bitnami
helm search repo bitnami/
helm install mysql bitnami/mysql -f sql-replica.yaml

3. Deploy phpmyadmin instance using yaml files on EC2 Node

kubectl apply -f mysql-secret.yaml
kubectl apply -f mysql-configmap.yaml
kubectl apply -f phpmyadmin.yaml

4. Port-forward traffic coming to localhost

Forward traffic from your local machine's port 8081 to the phpmyadmin-service service's port 8081. kubectl port-forward svc/phpmyadmin-service 8081:8081

5. Access phomyadmin in browser on

localhost:8081

EXERCISE 3: Deploy your Java application
You deploy your Java application using Fargate with 3 replicas and same setup as before

Solution:

1. You need to create a new namespace for the fargate profile:

kubectl create namespace my-app

2. Create Key (login to Registry and create Secret in K8S)

DOCKER_REGISTRY_SERVER=https://index.docker.io/v1/
DOCKER_USER=your docker username
DOCKER_EMAIL=your dockerhub email
DOCKER_PASSWORD= dockerhub pwd

kubectl create secret -n my-app docker-registry my-registry-key1 --docker-server=$DOCKER_REGISTRY_SERVER --docker-username=$DOCKER_USER --docker-password=$DOCKER_PASSWORD --docker-email=$DOCKER_EMAIL

3. Execute following commands

kubectl apply -f mysql-secret.yaml -n my-app
kubectl apply -f mysql-configmap.yaml -n my-app
kubectl apply -f deployment.yaml -n my-app

*** Fix: CrashLoop for Java APP!!! ***

EXERCISE 4
EXERCISE 5
EXERCISE 6