Know the basics of Kubernetes: https://www.youtube.com/watch?v=PH-2FfFD2PU&t=3s.
Know the basics of kubectl commands.
Know Kubernetes Kubernetes Resources via YAML, Deployments, Replica Sets, and Pods: https://www.youtube.com/watch?v=ohSUtEfDefc.
Know how to manage env values, secrets of any service deployed in Kubernetes: https://www.youtube.com/watch?v=OW244LxB4oI.
Know how to port forward to a pod running inside k8s cluster and work locally https://www.youtube.com/watch?v=TT3nd5n5Yus.
Know sops to secure your keys/credentials: https://www.youtube.com/watch?v=DWzJ87KbwxA.
Choose your cloud and follow the instructions to set up a Kubernetes cluster before moving on to the deployment.
Finally, clean up the cluster setup if you wish, using the following command. This will delete the entire cluster and other cloud resources that were provisioned for the DIGIT setup.
We have successfully created infra on cloud, and deployed DIGIT in the cluster.
The Amazon Elastic Kubernetes Service (EKS) is one of the AWS services for deploying, managing, and scaling any distributed and containerised workloads. Here we can provide the EKS cluster on AWS from the ground up and using an automated way (infra-as-code) using terraform and then deploy the DIGIT services config-as-code using Helm.
Know about EKS: https://www.youtube.com/watch?v=SsUnPWp5ilc.
Know what Terraform is: https://youtu.be/h970ZBgKINg.
AWS account with the admin access to provision EKS service. You can always subscribe to a free AWS account to learn the basics and try, but there is a limit to what is offered as free. For this demo, you need to have a commercial subscription to the EKS service, if you want to try out for a day or two, it might cost you about Rs 500 - 1000. (Note: Post the demo, for the internal folks, eGov will provide a 2-3 hours time-bound access to eGov's AWS account based on the request and the available number of slots per day).
Install Kubectl on your local machine that helps you interact with the Kubernetes cluster.
Install Helm that helps you package the services along with the configurations, envs, secrets, etc, into a Kubernetes manifests.
Install the Terraform version (0.14.10) for the Infra-as-Code (IaC) to provision cloud resources as code and with desired resource graph and also it helps to destroy the cluster in one go.
Install AWS CLI on your local machine so that you can use AWS CLI commands to provision and manage cloud resources on your account.
Install AWS IAM Authenticator that helps you authenticate your connection from your local machine so that you should be able to deploy DIGIT services.
Use the AWS IAM User credentials provided for the Terraform (Infra-as-code) to connect with your AWS account and provision cloud resources.
You will get a Secret Access Key and Access Key ID. Save them.
Open the terminal and run the following command. You have already installed the AWS CLI, and you have the credentials saved. (Provide the credentials. You can leave the region and output format blank).
The above will create the following file in your machine as /Users/.aws/credentials.
Before we provision cloud resources, we must understand what resources need to be provisioned by Terraform to deploy DIGIT.
The following picture shows the key components (EKS, Worker Nodes, Postgress DB, EBS Volumes, Load Balancer).
Considering the above deployment architecture, the following is the resource graph we will provision using Terraform in a standard way so that every time and for every env, it will have the same infra.
EKS control plane (Kubernetes master)
Work node group (VMs with the estimated number of vCPUs, memory)
EBS volumes (Persistent volumes)
RDS (PostGres)
VPCs (Private network)
Users to access, deploy, and read-only
Ideally, one would write the Terraform script from the scratch using this doc.
Here, we have already written the Terraform script that provisions the production-grade DIGIT infra and can be customised with the specified configuration.
Let's clone the DIGIT-DevOps GitHub repo where the Terraform script to provision the EKS cluster is available. Below is the structure of the files:
Example:
VPC Resources:
VPC
Subnets
Internet Gateway
Route Table
EKS Cluster Resources:
IAM Role to allow EKS service to manage other AWS services.
EC2 Security Group to allow networking traffic with the EKS cluster.
EKS Cluster.
EKS Worker Nodes Resources:
IAM role allowing Kubernetes actions to access other AWS services.
EC2 Security Group to allow networking traffic.
Data source to fetch the latest EKS worker AMI.
AutoScaling Launch Configuration to configure worker instances.
AutoScaling Group to launch worker instances.
Database
Configuration in this directory creates a set of RDS resources, including DB instance, DB subnet group, and DB parameter group.
Storage Module
Configuration in this directory creates EBS volume and attaches it together.
The following main.tf with create s3 bucket to store all the state of the execution to keep track.
iFix-DevOps/Infra-as-code/terraform/sample-aws/remote-state
main.tf.
The following main.tf contains the detailed resource definitions that need to be provisioned.
Dir: iFix-DevOps/Infra-as-code/terraform/sample-aws
You can define your configurations in variables.tf and provide the env-specific cloud requirements so that using the same Terraform template, you can customise the configurations.
Following are the values you need to mention in the following files. The blank ones will be prompted for inputs during execution.
variables.tf
Use this URL https://keybase.io/ to create your PGP key to create both public and private keys in your machine. Upload the public key into the keybase account that you have created, give it a name, and ensure that you mention that in your Terraform. This allows you to encrypt sensitive information.
Example: User keybase user in eGov case is "egovterraform" that needs to be created and the public key needs to be uploaded here: https://keybase.io/egovterraform/pgp_keys.asc
You can use this portal to decrypt your secret key. To decrypt a PGP message, upload the PGP message, PGP private key, and passphrase.
Now that we know what the Terraform script does, the resources graph that it provisions, and what custom values should be given to your env, let us begin to run the Terraform scripts to provision infra required for deploying DIGIT on AWS.
First CD into the following directory, run the following command 1-by-1, and watch the output closely.
Upon successful execution, the following resources get created, which can be verified by the command "terraform output".
s3 bucket: to store terraform state.
Network: VPC, security groups.
IAM users auth: using keybase to create admin, deployer, the user. Use this URL https://keybase.io/ to create your own PGP key to create both public and private keys in your machine. Upload the public key into the keybase account that you have just created, give it a name, and mention that in your terraform. This allows you to encrypt sensitive information.
Example: User keybase user in eGov case is "egovterraform" that needs to be created, and public keys need to be uploaded here: https://keybase.io/egovterraform/pgp_keys.asc
You can use this portal to decrypt your secret key. To decrypt a PGP message, upload the PGP message, PGP private key, and passphrase.
EKS cluster: with master(s) & worker node(s).
Storage(s): for es-master, es-data-v1, es-master-infra, es-data-infra-v1, zookeeper, kafka, kafka-infra.
Use this link to get the kubeconfig from EKS in order to get the kubeconfig file and connect to the cluster from your local machine. This enables you deploy DIGIT services to the cluster.
Finally, verify that you can connect to the cluster by running the following command.
You are all set to deploy the product.