.
Java App Deployment on Kubernetes Cluster
github repo for project files; Project Source

Prerequisites
- AWS account
- Registered DNS name
Note: Instance sizes for this project are no on free tier, delete immediately after project completion.
Step-1: Create an EC2 instance
We will launch an Ec2 to install kOps with below properties.
Name: kops
AMI: Ubuntu 20.04
InstanceType: t2.micro
SecGrp: allow SSH on port 22 from MyIP
KeyPair: create a new keypair
Step-2: Create S3 bucket
- Create an S3 bucket with details below to store the state of Kops so we can run our Kops command from anywhere as long as it is pointed to our s3 bucket.
Bucketname: Vprofile-kops-state1993
Step-3: Create IAM user
- Create an IAM user for our awscli with details below:
Username: Kops-admin
Attach policies: Adminstrator Access
Be sure to download the credentials.

Step-4: Create Route53 HostedZone
- Create Hosted Zone in Route53 with details below
Domain Name: kubevpro.<yourdomain-name.com>
Then we will create 4 NS values to our Registered domain as NS Record
.


Step-5: Login Ec2 and configure awscli
Now that we have our IAM user, S3 bucket and Domain setup, we can login and configure our ec2 instance.
- Log in to your ec2 instance and generate ssh-key which would be used by our Kops.
- Install and configure aws cli with commands below
sudo apt update && sudo apt install awscli -y
aws configure
then add the aws access key and secret key you already created and downloaded alongside your ec2 instance region.
Output “Json”
Step-6: Setup kOps Cluster
- Install and setup Kubectl with commands from the documentation link here https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/
- Next, install Kubernetes with Kops with documentation link here https://kubernetes.io/docs/setup/production-environment/tools/kops/
- Verify Domain with the command below
nslookup --type=ns kubevpro.<yourdomain-name.com>
you should get an output looking like this, if you completed your installations correctly.

Now we are going to run Kops command that will create our kubernetes cluster with details below:(Note: Don’t forget to replace your domain name and s3 bucket name in the command.)
kops create cluster --name=kubeapp.aws-devops-journey-of-rumeysadogan.net
--state=s3://kubeapp-kops-state --zones=us-east-1a,us-east-1b
--node-count=1 --node-size=t3.small --master-size=t3.medium
--dns-zone=kubeapp.aws-devops-journey-of-rumeysadogan.net
--node-volume-size=8 --master-volume-size=8
kops create cluster --name=kubevpro.irvingpictures.co
--state=s3://vprofile-kops-state1993 --zones=us-west-1b,us-west-1c
--node-count=2 --node-size=t3.small --master-size=t3.medium --dns-zone=kubevpro.irvingpictures.co
--node-volume-size=8 --master-volume-size=8

- Run the command below to update cluster, also run this command whenever you make any change to your cluster.
kops update cluster --name kubevpro.irvingpictures.co --state=s3://vprofile-kops-state1993 --yes --admin

- Validate your cluster after 10–15 minutes with the command below:
kops validate cluster --state=s3://vprofile-kops-state1993
If all is good, you’ll get an output like in the image below.

- Note: Kubectl uses cat /Users/mac/.kube/config to connect to the cluster.
- To view nodes, use the the command <kubectl get nodes>



Step-7: Create Volume for DB Pod
We need to create an EBS volume to store mySQL data. Use below command to create one.
aws ec2 create-volume
--availability-zone us-east-1a
--volume-type gp2
--size 3
--tag-specifications 'ResourceType=volume,Tags=[{Key=KubernetesCluster,Value=kubevpro.irvingpictures.co}]'
Next, label the nodes with zone=us-west-1b
and zone=us-west-1c
accordingly. To be sure that we are running our DB pod in the same zone our EBS volume created, we will create labels for our nodes with the commands below:
kubectl describe node i-0b181a16c01f0a1d4 | grep us-west-1
kubectl label nodes i-09a3d0bfbab45b066 zone=us-west-1c
kubectl get nodes --show-labels
Step-8: Source Code Review
You can find all kubernetes manifest files by cloning this repository.
Clone this repo to your ec2. Make necessary file changes, before applying kubectl
commands.
https://github.com/rumeysakdogan/kube-app.git
In Project-12, we containerized the vprofile application and pushed it to DockerHub.
We will use the images below with :VI tag from DockerHub repository in our K8s manifests.

Our vprofile application is using the application.properties
file below. We need to create Kubernetes services with the same name given in this file for application to connect to them.
#JDBC Configutation for Database Connection
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://vprodb:3306/accounts?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
jdbc.username=root
jdbc.password=vprodbpass
#Memcached Configuration For Active and StandBy Host
#For Active Host
memcached.active.host=vprocache01
memcached.active.port=11211
#For StandBy Host
memcached.standBy.host=vprocache02
memcached.standBy.port=11211
#RabbitMq Configuration
rabbitmq.address=vpromq01
rabbitmq.port=15672
rabbitmq.username=guest
rabbitmq.password=guest
#Elasticesearch Configuration
elasticsearch.host =vprosearch01
elasticsearch.port =9300
elasticsearch.cluster=vprofile
elasticsearch.node=vprofilenode
Step-9: Kube secret for passwords
In application.properties file, we have db password and rabbitMQ password. We will encode these values and create a K8s secret file as in given under kubernetes
directory.


Step-10: DB Deployment & Service Definition
Create a K8s DB deployment and service file as given under ourkubernetes
directory.

Step-11: Memcached Deployment & Service Definition
Create a K8s MC deployment and ClusterIP type service file as in given under kubernetes
directory. Run the commands below to create files:
kubectl apply -f mcdep.yml
kubectl apply -f mc-CIP.yml
Step-11: RabbitMQ Deployment & Service Definition
Create a K8s RMQ deployment and ClusterIP type service file as in given under kubernetes
directory. Run the commands below to create files:
kubectl apply -f rmq-dep.yml
kubectl apply -f rmq-CIP.yml
We can check the resources created with below command:
kubectl get all

Step-12: Application Deployment & Service Definition
Create a K8s Application deployment and LoadBalancer type service file as in given under kubernetes
directory. Run below commands to create files:
kubectl apply -f vproapp-dep.yml
kubectl apply -f vproapp-svc.yml
Step-13: Create Route53 Record for Application Load Balancer
We will create a record with Alias to Load balancer.
Lets validate our application from browser with our new dns name.

We validated DB by successfully log in with admin_vp/admin_vp username & pwd.

We can validate RabbitMQ service.

Lastly, we can verify our memcached service.

Step-14: Cleanup
We will start with deleting our kubernetes services first.
Then we will delete our cluster, s3 bucket, Route53 Hosted zone.
kops delete cluster --name kubevpro.irvingpictures.co --state=s3://vprofile-kops-sta