Deploy Cloud-Native REST API to AWS Kubernetes Cluster

Deploy Cloud-Native REST API to AWS Kubernetes Cluster

Agenda:

This tutorial will show you how to create fully functional production-ready cloud-based REST API, which is ready to serve requests 24/7 and save data to MySQL database.

As a fully-working example, I exposed REST API on my registered domain with Swagger UI:

The source code for this example is available on github:

The tutorial was inspired by this super practical Udemy course, created by Kalyan Reddy

I will not attempt to duplicate all information from this course, so I really recommend you to use this course as an actual step-by-step guide. This tutorial will just provide the general ideas inspired by this course.

Story:

AWS EKS Kubernetes-Masterclass course will be interesting to all developers who want to create fully-functional cloud-native environment on AWS and easily deploy their own portfolio applications or prototypes to show them to customers.

user-management source-code example contains Spring Boot application with REST API exposed by Swagger UI + Kubernetes manifest files required to deploy this application to AWS Kubernetes Cluster

  1. Build docker image with mvn clean install
  2. Push docker image to Docker Hub (replace "skyglass" repository, with the name of your docker hub repository in "pom.xml" docker plugin configuration)
  3. Setup Kubernetes Cluster on AWS with 1 or 2 worker nodes. See AWS EKS Kubernetes-Masterclass course for more details.
  4. I recommend adding "--spot" flag when you create nodegroup:
eksctl create nodegroup --cluster=eksdemo1 --region=us-east-1 --name=eksdemo1-ng-private1 --node-type=t3.medium --nodes-min=1 --nodes-max=1 --node-volume-size=0 --ssh-access --ssh-public-key=kube-demo --managed --spot --asg-access --external-dns-access --full-ecr-access --appmesh-access --alb-ingress-access --node-private-networking

Spot instance for "t3.medium" costs $0.0125 per Hour, which is 3.3 times less, than on-demand price for the same instance: $0.0416. See the full pricing info on spot instances here: https://aws.amazon.com/ec2/spot/pricing. Please, note that "t2.micro", which is a part of the free-tier, will not work for this example, because you need at least 3 pods.

5. user-management source-code example uses H2 in-memory database, but you can easily switch to MySQL database as an external AWS RDS service by switching to "mysqlaws" spring boot profile

6. Register domain with AWS Route 53

7. Register certificate for this domain to enable secure HTTPS connection

8. Replace "skyglass/user-management:1.0.0" with the name of your docker image in "02-UserManagementMicroservice-Deployment.yml"

9. Replace "users.skycomposer.net" in "kubernetes-old/07-ALB-Ingress-SSL-Redirect-ExternalDNS.yml" with "users.{your_registered_domain_name}"

10. Replace "alb.ingress.kubernetes.io/certificate-arn" in "kubernetes/07-ALB-Ingress-SSL-Redirect-ExternalDNS.yml" with arn of your certificate (you can find it in AWS Certificate Manager)

11. Run kubernetes manifest files from the user-management source-code "kubernetes" and "kubernetes-old" folders. ("kubernetes-old" folder is deprecated: see more details in my new post here: https://www.dhirubhai.net/posts/michaelsklyar_udemy-course-completion-certificate-activity-6802683768663511040-UlD6 )

12. Kubernetes manifest files will create Ingress Resource, which will expose your REST API.

13. Kubernetes manifest files will also create External DNS, which will secure your REST API with HTTPS connection, registered to your domain.

14. After deploying kubernetes manifest files you can use User Management Microservice REST API for creation of new users and showing the list of registered users (see https://users.skycomposer.net/usermgmt/swagger-ui/index.html as an example)

15. Notification Microservice will send confirmation e-mail to the registered users with Amazon Simple Email Service

The estimated cost of such production environment on AWS should be about 100 Euros per month.

No alt text provided for this image

?

This is a very simple application with a very simple UI, but it is in fact based on a quite non-trivial, feature-rich and fully-functional AWS Kubernetes Cluster Environment setup, which you can see on the diagram.

The good news is that it is not as hard as it seems, and if you are ready to spend several days to understand this process, you will never have to worry about deploying your applications to the cloud anymore. Just use your development skills to create amazing applications and show them to the customer on your own registered domain, which you totally control!

Kubernetes is a great tool, which significantly simplifies deployment of microservices in a cloud-native way. The advantage of "cloud-native" development is that after you start and test your application locally, you can easily create docker image and deploy it to AWS Kubernetes cluster without any code changes! If you ever used different maven profiles for local and production deployment, you will be glad to hear that you don't have to do it anymore.

The same code, which you run locally, will be deployed to the cloud.

Summary:

Do you remember those old times when you had an amazing application to offer, but had no idea how to make it available on the Web? Long time ago, you had to throw your application over the wall to specially trained DevOps engineers, who would take care about the rest of the process. If you ever wanted to deploy your own application, you would have to go down to the basement, where long-haired sysadmin in black "Metallica" T-Shirt lived, offering him a large box of beer to perform the magic ritual of deployment.

There is good and bad news:

  1. Good news, you don't have to rely on anyone else anymore, to share your code with the world. AWS and Kubernetes are your best friends now! :)
  2. Bad news: AWS doesn't accept beer, only credit cards. :)

Have fun!

要查看或添加评论,请登录

Mykhailo Skliar的更多文章

社区洞察

其他会员也浏览了