Steps to deploy a node application into Kubernetes EKS
In this tutorial
- We’ll deploy a simple node-express application into EKS
- Configure nginx-ingress so that we can access via HTTP
- Configure ssl/tls certificate so that we can access via HTTPS
Link to GitHub repository
References
- https://www.youtube.com/watch?v=_jEgzqyUWKE
- https://github.com/antonputra/tutorials/tree/main/lessons/046
Prerequisites
- Install `aws` command line utility
- Install `eksctl` command line utility
- Generate access key and secret from https://console.aws.amazon.com/iam/home#/security_credentials$mfa

- Connect to aws using the command `aws configure`. Use the above generated `AWS Access Key ID and AWS Access Secret`.
- Verify eksctl installation using the command `eksctl version`
- Verify aws configuration using the command `aws iam get-user`
Create sample node app
- Create a project directory `mkdir ~/node-kubernetes-eks-deploy`
- Switch to project direcoty `cd ~/node-kubernetes-eks-deploy`
- Create directory `mkdir app`
- Create a simple `express` app
- Sample `server.js` file
- Create a docker file named `Dockerfile` inside the folder `app`
- Create a docker ignore file named `.dockerignore` with following contents
- Now build docker image `docker build -t testkubernets:v1.0.0 -f Dockerfile .`
- Verify by running `docker images`

Push docker images into eks repository in AWS
- Open aws console `https://ap-south-1.console.aws.amazon.com/ecr/repositories` and click on `Create Repository`
- Choose `Visibility settings` as private
- Give any name, say `testkubernets`
- Leave other fields with default values

- Now select the repository `aws-repository-list` and click `View Push Commands` button. Now you could see commands to push docker images into repository.

- Login using the login command from the above command list.
- Now tag the docker image created above. Use the command from the above list. Change the version name if requried. (default version name is `latest`) eg : `docker tag testkubernets:v1.0.0 913508394982.dkr.ecr.ap-south-1.amazonaws.com/testkubernets:v1.0.0`
- Verify it by running `docker images`

- Now push the docker images into repository using the docker push command in the above command list. `docker push 913508394982.dkr.ecr.ap-south-1.amazonaws.com/testkubernets:v1.0.0`
- Wait for a few minutes to complete the command execution.
Create EKS Cluster
- Create a yaml script in project root directory named `eks.yaml` with following contents.
- `cd ..`
- Change the aws region in the yaml script — eks.yaml
- Create the cluster using the command `eksctl create cluster -f eks.yaml`
- At any point of time, if you would like to delete the cluster, use the command `eksctl delete cluster -f eks.yaml`
- Wait for a few minutes to complete the cluster creation process.
Deploy node app into Kubernetes
- Create a folder `k8s` in project root folder
- Create a yaml script named `1-testkubernetes.yaml`
- Apply the above yaml script using the command `kubectl apply -f k8s/1-testkubernetes.yaml`

- Verify it by listing the pods `kubectl get pods -n production`

- List services using the command `kubectl get svc -n production`

- Forward local 8080 port to kubernetes `kubectl -n production port-forward svc/testkubernetes 8080:8080`
- Now open localhost:8080 in browser and verify it. Then CNTRL+C to stop port forwarding.
Deploy nginx ingress controller into Kubernetes
- Create a yaml script `k8s/2-nginx-ingress.yaml`
- Deploy it using the command `kubectl apply -f k8s/2-nginx-ingress.yaml`

- List the pods `kubectl get pods -n ingress-nginx`
- List the services `kubectl get svc -n ingress-nginx`

Create ingress for NodeJs
- Create a yaml script `k8s/3-http-ingress.yaml`

- Deploy it using the command `kubectl apply -f k8s/3-http-ingress.yaml`
- Verify it `kubectl get ing -n production`

- Copy the address and issue command `nslookup <address copied>`
- Verify it using the command `curl — resolve testkubernetes.5by1.com:80:<ip address from above command> http://testkubernetes.5by1.com/devops`
Create https ingress for NodeJs
- If you have ssl certificates, you could configure ingress for https protocol.
- Delete current secrets in the namespace if any, by using the command `kubectl delete secret tls tls-secret — namespace=production`. Where `tls-secret` is the name. We can give any name.
- Create secret using the command `kubectl create secret tls tls-secret — namespace=production — key <path to private key> — cert <path to certificate file (bundle.crt)>`
- Now change the `3-http-ingress.yaml` as in the github.
- Deploy it into kubernetes using the command `kubectl apply -f k8s/3-http-ingress.yaml`
- Find host name using `kubectl get ing -n production`
- Find ip address using `nslookup ac5a031917141484f88de73d0055ffcf-dc45f856834aad99.elb.ap-south-1.amazonaws.com`
- Verify it using `curl — resolve testkubernetes.5by1.com:443:15.206.13.238 https://testkubernetes.5by1.com/devops`
Update CNAME in hosting provider
- Update CNAME and point the sub domain to the above mentioned host address.
- Now you can access the application using https://your-sub.domain.com