"Unlock the power of AWS EKS with this step-by-step guide! Learn how to effortlessly deploy a Python-based microservice application on Amazon's Elastic Kubernetes Service (EKS), harnessing the scalability and efficiency of containers in the cloud. Dive into the essentials of seamless deployment, optimizing your workflow for a robust, scalable, and dynamic application environment."
Credits for Video Nasiullha Chaudhari
YouTube video: youtu.be/jHlRqQzqB_Y?si=oVjnBLWD5JEs_dFW
GitHub Repo: https://github.com/N4si/microservices-python-app
Articles Credit: Ajay Kumar Yegireddi
For EKS,IAM,Node creation via Script refer video by Ajay Kumar: https://www.youtube.com/watch?v=5-PZnYaoZUM
For Starting with we need to have some pre-requisite.
AWS Instance-- Kindly go with t2.medium OS Ubuntu and Version would be 20.04 because its is stable version for kubectl.
HELM
AWS CLI
Python
Install kubectl
Database: MongoDB and PostgreSQL
Once you done with creation of AWS instance installation of required package mentioned above you can wit creating of IAM role.
Created a EC2 Instances
IAM role creation
Click on Search filed, type IAM
Click on "Role"
Click on AWS Service
Search for "EC2" and Click on "Next"
Now, search of AdministratorAccess & select as seen on below image.
and Click on "Next"
On the Role name, give name as you require and
Click on Create Role
After creation of IAM role go to EC2 Instance
and follow the below step
Select instance --> Actions --> Security --> Modify IAM role
& click on Update IAM role.
Now you can connect to the server.
Once you login to the server you can fork the repo and make a clone of it by executing below command.
#git clone "repo url"
Check Version by executing below command.
# Check Versions
terraform -version
kubectl version --client --short
aws --version
helm version --short
python3 --version
psql --version
mongod --version
docker version
Now go inside Eks-terraform to provison Eks cluster with terraform files
Now you can see terraform files and make sure to change your region and S3 bucket name in the backend file.
Now initialize
Validate the code
Now let's see plan
Let's apply to provision by executing below command
#terraform apply --auto-approve
It take some time to complete the process. After completion there will be one EKS cluster, IAM role for EKS and Node Server will be created.
EC2 Instance:
EKS Cluster created
IAM Role:
Will update the Kubernetes configuration by executing below command
#aws eks update-kubeconfig --name --region
Let's go inside the Helm_charts
cd Helm_charts
ls
Now go inside MongoDB and apply the k8s files
No execute the below command
kubectl get all
To check the Persistent volume
kubectl get pv
Then go to Postgres folder and edit the init.sql file
Enter your email and password
Apply the Kubernetes files using Helm
helm install postgres .
Let's see the pods and deployments
Add some rules to Node Server
Now copy the public IP of the Node group ec2 instance and execute below command.
mongosh mongodb://<username>:<pwd>@<nodeip>:30005/mp3s?authSource=admin
#username use nasi
#pwd nasi1234 #if you want to update them go to mongo secrets.yml file and update
#nodeip #use your node ec2 instance ip
Connect to the Postgres database and copy all the queries from the "init.sql" file.
Now add the init.sql file and Use your mail for values
CREATE TABLE auth_user (
id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
email VARCHAR (255) NOT NULL,
password VARCHAR (255) NOT NULL
);
--Add Username and Password for Admin User
-- INSERT INTO auth_user (email, password) VALUES ('thomasfookins007helby@gmail.com', '123456');
INSERT INTO auth_user (email, password) VALUES ('<User your mail>', '123456');
Now provide \d to see data tables
Now provide the below command to see the authentication user
Now go to RabbitMQ directory
And execute below command
helm install rabbit .
Now see the deployments and pods
kubectl get all
Now copy the public IP of the node group Ec2 instance
<Node-ec2-public-ip:30004>
You will get this page Just login
username is guest
password is guest
This will the dashboard once you will login
Click on Queues
After Queue for Mp3 and Video it will show like this
Microservices
Got to SRC directory as shown below
Go to directory as shown below
Now let's see whether it created pods or not
kubectl get all
Now come back to another Microservice and do the same process
And execute below command
kubectl apply -f .
Now come back to another microservice and do the same process
And execute the below command
kubectl apply -f .
Check for deployments and service
kubectl get all
GMAIL PASSWORD
Now let's create a Password for Gmail to get Notifications
Open your Gmail account in the browser and click on your profile top right.
Click on Manage your Google account
Now click on Security
Two-step verification should be enabled
If not, enable it
Now click on the search bar and search for the APP
Click on App passwords
Come back to Putty and update the secret.yaml file for notification service microservice
cd ../..
cd notification-service
cd manifest
sudo vi secret.yaml
#change your mail and password that Generated.
vi secret.yaml
apiVersion: v1 kind: Secret metadata: name: notification-secret stringData: GMAIL_ADDRESS: "projectsdevops8@gmail.com" GMAIL_PASSWORD: "your generated password" type: Opaque
Now apply the manifest files
kubectl apply -f .
Now come to the assets directory
cd /home/ubuntu/microservice-python-app
cd assets
ls
curl -X POST http://nodeIP:30002/login -u <email>:<password>
Copy the token and paste it inside a base 64 decoder you will get this
change JWT Token and node ec2 IP.
curl -X POST -F 'file=@./video.mp4' -H 'Authorization: Bearer <JWT Token>' http://nodeIP:30002/upload
It will send an ID to the mail
Let's check the mail
Copy that ID and paste it inside the below command with the JWT token and fid
curl --output video.mp3 -X GET -H 'Authorization: Bearer ' "http://nodeIP:30002/download?fid="
#change Bearer with JWT token
#nodeIp
#fid token at end
It will download an MP3 file
You can see it's created mp3 file and you can play it.
aws s3 cp your-file s3://your-bucket/your-prefix/
You can copy it s3 bucket and download and you can listen to it.
Destroy
Now go inside Eks-terraform directory
To delete eks cluster
terraform destroy --auto-approve
It will take 10 minutes to delete the cluster
Once that is done
Remove your Ec2 instance and Iam role.