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
brew tap weaveworks/tap
brew install weaveworks/tap/eksctl
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
# 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
kubectl get node
eksctl get fargateprofile --cluster jane-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.
export KUBECONFIG=/Users/jfoerster008/.kube/config
helm repo add bitnami https://charts.bitnami.com/bitnami
helm search repo bitnami/
helm install mysql bitnami/mysql -f sql-replica.yaml
kubectl apply -f mysql-secret.yaml
kubectl apply -f mysql-configmap.yaml
kubectl apply -f phpmyadmin.yaml
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
localhost:8081
EXERCISE 3: Deploy your Java application
You deploy your Java application using Fargate with 3 replicas and same setup as before
kubectl create namespace my-app
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
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!!! ***