In part 1, I created a full-stack web app, added Atlas Mongodb, integrated Firebase for authentication, containerized the app using Docker, set up GitHub actions, and pushed it to Elastic Container Registry. Now, we will deploy the Docker images to Kubernetes (EKS) and expose them securely to the public using in Docker, ECR, Amazon Kubernetes (EKS) and an ingress LoadBalancer.
Prerequisites
- Docker images pushed to ECR ( which we did in the first part)
- An AWS EKS (Elastic Kubernetes Service) cluster - we need to create this one
- kubectl installed locally in our laptop
- aws CLI installed locally ( if you dont have one)
- eksctl installed (helpful in setting up the EKS but its optional)
AWS CLI Installation
I am using Macbook so I will initialy install awscli
- Use
brew install awsclimarygracezabala@Mac ~ % brew install awscli ==> Auto-updating Homebrew...
Execute AWS Configure and add the AWS credentials you created with IAM role for development. This saves to ~/.aws/credentials locally.

- Restart your IDE (Visual Studion Code) - I need to restart my Vscode so it can see the credential files (part of my troubleshooting)
Additional IAM roles to be added for EKS
| Permission Policy | Why it's Needed | Attach To |
|---|---|---|
AmazonEKSClusterPolicy | Manage and interact with EKS clusters | IAM User |
AmazonEKSWorkerNodePolicy | Allow nodes (EC2) to register to EKS | IAM Role for EC2 (for worker nodes) |
AmazonEKS_CNI_Policy | Manage networking inside EKS (VPC CNI plugin) | IAM Role for EC2 (for worker nodes) |
AmazonEC2FullAccess (optional) | Create/manage EC2 instances for EKS | IAM User (for eksctl to create nodes) |
Create EKS Cluster
Create EKS Cluster Role.
This is needed tp:
- Create EKS cluster
- Used by the Kubernetes Control Plane
- Allows EKS to:
- Create/manage networking
- Attach load balancers
- Call APIs like Auto Scaling, CloudWatch, etc.
- You typically assign:
AmazonEKSClusterPolicy- VPC-related permissions if needed



Edit Trust Policy of EKS Cluster Role

Add additional permission to the role
- AmazonEKSBlockStoragePolicy
- AmazonEKSComputePolicy
- AmazonEKSLoadBalancingPolicy
- AmazonEKSNetworkingPolicy
2. Create EKS Node IAM role.
For our app in the recent blog, React + Node.js + MongoDB app running in EKS.
- This is required when creating a Node Group (EC2 worker nodes)
- The policy is Attached to each EC2 node
- It Allows EC2 nodes to:
- Register themselves with the EKS cluster
- Pull container images from ECR
- Use VPC CNI plugin (networking)
- Log to CloudWatch (optional)
- You must assign:
AmazonEKSWorkerNodePolicy- Allows the node to join EKS clusterAmazonEC2ContainerRegistryReadOnly- Allows pulling container images from ECRAmazonEKS_CNI_Policy- Enables VPC networkingCloudWatchAgentServerPolicy- to enable logging
Steps to Crear Node IAM Role
- Go to IAM > Roles > Create role
Choose "AWS service" ➝ EC2

- Attach these policies:
AmazonEKSWorkerNodePolicyAmazonEKS_CNI_PolicyAmazonEC2ContainerRegistryReadOnlyCloudWatchAgentServerPolicy
I named it
eks-node-role
- Select this role when creating the node group
Go to EKS in AWS. Then click create cluster. Create Kubernetes CLuster in AWS
I named it eks-cluster-react-fullstack.Assign the Cluster IAM Role and the Node IAM Role

Configure the kubernetes Cluster
Configure
kubectlto Use EKS Clustermarygracezabala@Mac back-end % aws eks update-kubeconfig --region us-east-1 --name eks- cluster-react-fullstack Cluster status is CREATING marygracezabala@Mac back-end %Wait for the cluster to finish

Execute these commands again
marygracezabala@Mac back-end % aws eks update-kubeconfig --region us-east-1 --name eks-cluster-react-fullstack Added new context arn:aws:eks:us-east-1:443370678519:cluster/eks-cluster-react-fullstack to /Users/marygracezabala/.kube/config marygracezabala@Mac back-end % kubectl get nodes No resources found marygracezabala@Mac back-end %
Secure App with AWS Secrets Manager + IRSA
Now we’ll fetch secrets from AWS Secrets Manager using IAM Roles for Service Accounts (IRSA).
- Create secrets in AWS Secrets Manager (e.g., Firebase credentials, MongoDB username/password).
- Please see the link on how to create secrets in AWS secrets manager
- Update Node IAM Role (
eks-node-role-full-stack) to allow secrets access: { "Effect": "Allow", "Action": ["secretsmanager:GetSecretValue"], "Resource": "arn:aws:secretsmanager:REGION:ACCOUNT_ID:secret:react-blog-secrets-*" }
Install the aws-sdk module:
marygracezabala@Mac React Full Stack % npm install @aws-sdk/client-secrets-manager added 77 packages, and audited 90 packages in 4s 3 packages are looking for funding run `npm fund` for details found 0 vulnerabilities- To allow the application pods to securely access AWS Secrets Manager (instead of using
.envfiles or hardcoded credentials), I must create a Kubernetes service account mapped to an IAM role via IAM Roles for Service Accounts (IRSA).Check the OIDC Provider is Associated with the EKS cluster(eks-cluster-react-fullstack) we created previously

Create an IAM Policy for AWS Secrets Manager Access


- Create an IAM Role for the Kubernetes Service Account
- In the IAM Console, click Create role.
Select Web identity as the trusted entity type.

As you noticed above, I chose the OIDC Identity and addedsts.amazonaws.com as audience. To created oidc identity provider, follow these steps:
Choose your EKS cluster's OIDC provider from the dropdown.
This is the OIDC Information obtained from EKS cluster console

For Audience, enter
sts.amazonaws.com.
Click Next. Now you already how OIDC as Identity provider

After choosing web identity and added oid and audience,we can now continue creating the role. Click next and attach the
SecretsManagerReadAccesspolicy you created earlier.Please see the image below

Next create the role, I named the role as EKSSecretsAccessRole.

Take note of the arn of the EKSSecretsAccessRole as we will associate it with the Kubernetes service account that we will creat

- Create a Kubernetes Service Account and Associate the IAM Role
- Since the AWS Console doesn't support creating Kubernetes service accounts directly, you'll need to use
kubectl: - Ensure your
kubectlis configured to interact with your EKS cluster. Create a file named
service-account.yamlwith the following content (replace placeholders accordingly):First, create a yaml configuration in the directory
react-fullstack-app/ ├── back-end/ │ └── ... ├── front-end/ │ └── ... ├── k8s/ │ └── service-account.yaml ← create this one to create service-account for our kubernetes cluster ├── Dockerfile ├── .dockerignore ├── .gitignore └── README.mdNow in my local macbook, I will create k8s directory, and from the k8s directory, I will create
service-account.yamlmarygracezabala@Mac React Full Stack % mkdir k8s marygracezabala@Mac React Full Stack % cd k8s marygracezabala@Mac k8s % vi service-account.yamlservice-account.yamlapiVersion: v1 kind: ServiceAccount metadata: name: secrets-access-sa namespace: default annotations: eks.amazonaws.com/role-arn: arn:aws:iam::123456789012:role/EKSSecretsAccessRoleApply the configuration:
marygracezabala@Mac k8s % kubectl apply -f service-account.yaml serviceaccount/secrets-access-sa createdThis service account is now associated with the IAM role, allowing pods that use it to access AWS Secrets Manager securely.
- Since the AWS Console doesn't support creating Kubernetes service accounts directly, you'll need to use
Modify
/src/server.tsto fetch secrets at runtime using IRSA:import { SecretsManagerClient, GetSecretValueCommand } from '@aws-sdk/client-secrets-manager'; const secretsManager = new SecretsManagerClient({ region: process.env.AWS_REGION }); const secret = await secretsManager.send( new GetSecretValueCommand({ SecretId: 'react-blog-secrets' }) ); const credentials = JSON.parse(secret.SecretString || '{}');- Update Dockerfile and Build Again
Make sure that you set AWS Region in the .env variable
Reconfigure and rebuild my docker image after modifying the secret-fetching login in the server.ts
This blog is still ongoing and I will update other details soon.
No Comments