AWS Builder Center

Day 2: GitLab CI/CD — From Git Push to Amazon EKS

Building a secure, automated delivery pipeline using GitLab CI/CD, Terraform, Docker, Amazon ECR, IAM OIDC, and Amazon EKS

On Day -1, I focused on the foundations of DevOps — Linux, Git, GitHub, AWS fundamentals, IAM, and CI/CD concepts.
On Day 1, I explored Amazon EKS fundamentals and how Kubernetes workloads run on AWS.
Today, I moved one step further.
For Day 2, my focus was understanding how GitLab CI/CD can automate the journey from a developer's Git push to an application running on Amazon EKS.

The objective was not just to understand the commands, but to understand the architecture, responsibilities, security model, and troubleshooting approach behind the pipeline.



🚀 The Big Picture

A modern GitLab-to-AWS deployment can look like this:
Developer
|
| git push
v
GitLab Repository
|
v
.gitlab-ci.yml
|
v
GitLab CI/CD
|
v
GitLab Runner
|
+-----------------------+
| |
v v
Terraform Application
| |
v v
AWS Infrastructure Docker Build
|
v
Amazon ECR
|
v
Amazon EKS
|
v
Kubernetes Deployment
|
v
Pods

This creates an automated path:
Code → Pipeline → Infrastructure → Container → Registry → Kubernetes → Application
That is the core idea behind CI/CD-driven cloud deployment.



1. What is GitLab CI/CD?

GitLab CI/CD provides an automation framework for building, testing, securing, and deploying applications.
Without CI/CD, developers or operations teams may need to manually execute commands such as:
git pull
npm install
npm test
docker build
docker push
kubectl apply

A CI/CD pipeline turns these manual operations into an automated workflow.
For example:
Developer
|
| git push
v
Pipeline Trigger
|
v
Validate
|
v
Test
|
v
Build
|
v
Security Scan
|
v
Docker Image
|
v
ECR
|
v
EKS

The biggest advantage is consistency.
The same process can execute repeatedly without relying on someone remembering every manual command.



2. The  .gitlab-ci.yml  File

GitLab pipelines are commonly defined using:
.gitlab-ci.yml

For example:
stages:
- validate
- build
- deploy

validate:
stage: validate
script:
- echo "Validating application"

build:
stage: build
script:
- echo "Building application"

deploy:
stage: deploy
script:
- echo "Deploying application"

The important concept here is:
The CI/CD process itself becomes code.
This provides several benefits:
  • Version control
  • Code review
  • Repeatability
  • Auditability
  • Collaboration
  • Easier troubleshooting
If the pipeline changes, that change can be reviewed just like application code.



3. Understanding GitLab Runner

One of the most important concepts I focused on today was the GitLab Runner.
GitLab manages the pipeline, but the actual commands need an execution environment.
That's where the Runner comes in.
The flow is:
GitLab
|
| CI/CD Job
v
GitLab Runner
|
+---- Execute Terraform
+---- Run Tests
+---- Build Docker Images
+---- Run Security Scans
+---- Authenticate with AWS
+---- Deploy to Kubernetes

The Runner is therefore a critical component of the CI/CD architecture.
Depending on the organization's requirements, runners can be configured with different executors and environments.
For containerized workloads, a Runner can provide an environment capable of executing Docker and Kubernetes-related operations.



4. Terraform + GitLab CI/CD

Infrastructure should also be automated.
Instead of manually creating AWS resources through the AWS Management Console, Terraform allows infrastructure to be defined as code.
For example:
Terraform
|
+---- VPC
+---- Subnets
+---- Security Groups
+---- IAM
+---- ECR
+---- EKS
+---- Supporting AWS Resources

The pipeline can execute:
terraform init
terraform validate
terraform plan
terraform apply

A typical infrastructure workflow becomes:
Developer
|
v
GitLab
|
v
GitLab Runner
|
v
Terraform
|
v
AWS

This provides an important DevOps principle:
Infrastructure should be reproducible and version controlled.



5. Terraform Plan vs Apply

A production pipeline should distinguish between planning and changing infrastructure.

Terraform Plan

terraform plan

Terraform calculates what changes would be made.
For example:
Plan:
2 resources to add
1 resource to change
0 resources to destroy


Terraform Apply

terraform apply

Terraform actually makes those changes in AWS.
A safer production workflow can therefore be:
Git Push
|
v
Terraform Validate
|
v
Terraform Plan
|
v
Review
|
v
Approval
|
v
Terraform Apply

This separation becomes especially important when infrastructure changes can affect production workloads.



6. Docker: Packaging the Application

Once infrastructure is available, the application needs to be packaged.
Docker provides a consistent application packaging mechanism.
The basic flow is:
Application Source
|
v
Dockerfile
|
v
docker build
|
v
Docker Image

For example:
docker build -t myapp:latest .

The resulting image can then be pushed to Amazon ECR.



7. Amazon ECR

Amazon Elastic Container Registry (ECR) provides a managed container image registry within AWS.
The CI/CD flow becomes:
GitLab Runner
|
v
Docker Build
|
v
Docker Image
|
v
Amazon ECR

A production-oriented pipeline should generally avoid relying on mutable tags such as:
latest

A better approach is to use immutable identifiers such as:
myapp:1.0.15

or:
myapp:<git-commit-sha>

For example:
myapp:a81c93f

This makes it much easier to identify exactly which source version is running in EKS.



8. Amazon ECR → Amazon EKS

Once the container image is available in ECR, Kubernetes can deploy it to Amazon EKS.
The flow becomes:
GitLab
|
v
GitLab Runner
|
v
Docker Build
|
v
Amazon ECR
|
v
Amazon EKS
|
v
Kubernetes Deployment
|
v
Pods

A Kubernetes Deployment may reference an ECR image:
containers:
- name: backend
image: <AWS_ACCOUNT_ID>.dkr.ecr.<REGION>.amazonaws.com/backend:<TAG>

Kubernetes then schedules Pods using that image.
This creates a complete automated application delivery chain.



9. AWS Authentication — A Critical Part of CI/CD

One of the most important topics in CI/CD is authentication.
The pipeline needs permission to interact with AWS.
A traditional approach is storing:
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY

However, long-lived credentials create security and operational risks.
A modern approach is OIDC-based federation.
The concept is:
GitLab
|
| OIDC Identity Token
v
AWS IAM
|
| AssumeRoleWithWebIdentity
v
Temporary AWS Credentials
|
v
AWS Resources

Instead of storing a permanent AWS secret key in GitLab, the CI job can obtain temporary credentials by assuming an IAM role.
This is a much stronger security model when properly configured.



10. Why OIDC Matters

OIDC-based authentication provides several advantages:

No long-lived AWS access keys

Credentials are temporary.

Better security

The trust relationship can be restricted to specific GitLab projects, branches, environments, or other claims.

Better auditing

AWS CloudTrail can record role assumption activity.

Reduced secret management

There is less dependency on manually rotating static AWS credentials.
The security principle is:
Prefer short-lived credentials and least privilege over long-lived credentials.



11. IAM Least Privilege

OIDC alone does not automatically make a pipeline secure.
The IAM role still needs carefully designed permissions.
For example, a pipeline that only needs to push images to ECR should not necessarily have unrestricted administrator permissions.
Similarly, infrastructure deployment roles should have permissions appropriate to the infrastructure they manage.
The ideal architecture is:
GitLab
|
v
OIDC
|
v
IAM Role
|
v
Least-Privilege Permissions
|
+---- ECR
+---- EKS
+---- Required AWS Services

This follows the principle of least privilege.



12. Connecting GitLab CI/CD to EKS

Once the image is available in ECR, the pipeline needs to interact with the EKS cluster.
Conceptually:
GitLab Runner
|
v
AWS Authentication
|
v
EKS Authentication
|
v
kubectl
|
v
Kubernetes API Server
|
v
Deployment

For example:
aws eks update-kubeconfig \
--region $AWS_REGION \
--name $EKS_CLUSTER_NAME

Then the pipeline can execute Kubernetes commands such as:
kubectl apply -f k8s/

or update a Deployment to use a new image.



13. A Complete CI/CD Pipeline

Putting everything together:
Developer
|
| git push
v
GitLab Repository
|
v
GitLab CI/CD
|
v
GitLab Runner
|
+-------------+-------------+
| |
v v
Terraform Pipeline Application Pipeline
| |
v v
Terraform Validate Unit Tests
| |
v v
Terraform Plan Security Scan
| |
v v
Approval Gate Docker Build
| |
v v
Terraform Apply Image Scan
| |
v v
AWS Infrastructure Amazon ECR
|
v
Amazon EKS
|
v
Kubernetes Deployment
|
v
Pods

This is much closer to what a real-world DevOps platform may look like.



14. Adding Security and Quality Gates

A production pipeline should not simply:
Build → Deploy

Instead, it should introduce quality and security controls.
A more mature pipeline could be:
Code
↓
Validate
↓
Unit Tests
↓
SAST
↓
Dependency Scan
↓
Terraform Validate
↓
Terraform Plan
↓
Docker Build
↓
Container Image Scan
↓
Push to ECR
↓
Approval
↓
Deploy to EKS
↓
Health Check

This transforms CI/CD into a DevSecOps workflow.
Security becomes part of the delivery process instead of being performed only after deployment.



15. Production Approval Workflow

For development environments, automatic deployment may be appropriate.
For production, an approval mechanism can be introduced.
For example:
Developer
|
v
GitLab
|
v
Build
|
v
Test
|
v
Security Scan
|
v
Terraform Plan
|
v
Manual Approval
|
v
Terraform Apply
|
v
Deploy to EKS

This gives engineering teams a controlled production release process.



16. Environment Separation

As environments grow, we should avoid treating everything as one environment.
A common model is:
Development
|
v
Testing
|
v
Staging
|
v
Production

Terraform can maintain environment-specific configurations while reusing common modules.
For example:
terraform/
│
├── modules/
│ ├── vpc/
│ ├── eks/
│ ├── ecr/
│ └── iam/
│
└── environments/
├── dev/
├── staging/
└── prod/

This becomes particularly valuable as infrastructure grows.



17. Troubleshooting the Pipeline

One of the biggest lessons from this architecture is that a pipeline can fail at multiple layers.
The complete dependency chain looks like:
GitLab
↓
Runner
↓
Terraform
↓
AWS IAM
↓
Docker
↓
ECR
↓
EKS
↓
Kubernetes
↓
Application

Instead of randomly changing configurations, identify the failing layer first.



Terraform Failure

Check:
Terraform configuration
Provider configuration
AWS authentication
IAM permissions
Terraform state
Backend configuration
State locking




Docker Failure

Check:
Dockerfile
Build context
Dependencies
Base image
Runner environment
Disk space
CPU / Memory




ECR Failure

Check:
AWS authentication
ECR repository
IAM permissions
Docker login
Image tag
Registry URL




EKS Failure

Check:
AWS credentials
EKS cluster access
IAM permissions
Kubernetes authentication
Kubeconfig
Manifest
Namespace




Pod Failure

Check:
kubectl get pods
kubectl describe pod <pod-name>
kubectl logs <pod-name>

Then investigate:
ImagePullBackOff
CrashLoopBackOff
Pending
FailedScheduling
Readiness Probe failures
Liveness Probe failures

The key lesson is:
Troubleshoot from the outside in, following the dependency chain.



18. Observability Should Be Part of CI/CD

Deployment is not the final step.
After deployment, we should verify whether the application is actually healthy.
For example:
Deploy
|
v
Pod Created
|
v
Pod Running
|
v
Readiness Probe
|
v
Service Available
|
v
Application Health Check

A mature CI/CD system should verify deployment health rather than assuming:
kubectl apply = successful application

A successful Kubernetes deployment command does not necessarily mean the application is healthy.



19. What I Learned From Day 2

The biggest lesson from Day 2 is that CI/CD is an ecosystem, not a single tool.
Each component has a specific responsibility:
GitLab
↓
Source Control + Pipeline Orchestration

GitLab Runner
↓
Job Execution

Terraform
↓
Infrastructure as Code

Docker
↓
Application Packaging

Amazon ECR
↓
Container Image Registry

AWS IAM + OIDC
↓
Secure AWS Authentication

Amazon EKS
↓
Container Orchestration

Kubernetes
↓
Application Deployment

When these components are connected properly, we get an automated software delivery platform.



🎯 Key Takeaways

My key takeaways from Day 2:

1. CI/CD should be defined as code

The  .gitlab-ci.yml  file makes the delivery process version controlled and repeatable.

2. GitLab Runner is the execution engine

Understanding the Runner is essential when troubleshooting CI/CD jobs.

3. Infrastructure should be automated

Terraform allows AWS infrastructure to be created consistently and repeatably.

4. Containers provide portability

Docker packages applications into predictable deployment units.

5. ECR provides the image lifecycle

Container images can be stored and managed centrally before deployment.

6. EKS provides the runtime platform

Kubernetes manages application Pods, Services, scaling, and workload orchestration.

7. OIDC improves AWS authentication

Short-lived credentials are preferable to long-lived AWS access keys.

8. Security should be integrated into the pipeline

Security scans, IAM least privilege, image scanning, and approval gates should become part of the delivery workflow.

9. Troubleshooting should be layered

Always identify which component failed before modifying configuration.



🚀 Final Architecture

The complete mental model I built today is:
DEVELOPER
|
| git push
v
+------------------+
| GitLab |
| Repository + CI |
+--------+---------+
|
v
+------------------+
| GitLab Runner |
+--------+---------+
|
+--------------+--------------+
| |
v v
+-------------+ +-------------+
| Terraform | | Application |
+------+------+ +------+------+
| |
v v
AWS Infrastructure Docker Build
| |
| v
| Amazon ECR
| |
+-------------+---------------+
|
v
Amazon EKS
|
v
Kubernetes Deployment
|
v
Pods
|
v
Application

This architecture represents the journey:
Git Push → CI/CD → Infrastructure → Container → Registry → Kubernetes → Application
And that is the real value of DevOps automation.



🌱 What's Next — Day 3

Now that the GitLab → AWS → EKS workflow is clear, the next step is to go deeper into Terraform Infrastructure Automation.
For Day 3, I will focus on:
  • Terraform Modules
  • Remote State
  • State Locking
  • S3 Backend
  • Environment Separation
  • Variables and Outputs
  • Reusable Infrastructure
  • Terraform Plan vs Apply
  • CI/CD with Terraform
  • Production Approval Workflows
  • Infrastructure Security
The journey continues:
Day -1
AWS DevOps Foundations
↓
Day 1
Amazon EKS Fundamentals
↓
Day 2
GitLab CI/CD → AWS EKS
↓
Day 3
Terraform Infrastructure Automation

Learn. Build. Automate. Deploy. Repeat.



💡 Community Discussion

I'd love to hear from other AWS and DevOps practitioners:
How are you handling GitLab CI/CD authentication with AWS in your production environments?
Are you using:
  • OIDC + IAM Roles?
  • GitLab-managed runners?
  • Self-hosted runners?
  • Terraform Cloud?
  • GitLab environments with manual approvals?
  • Another approach?
Sharing different implementation patterns is one of the best ways to learn from the community.
#AWS #AWSCommunityBuilders #GitLab #GitLabCICD #DevOps #AmazonEKS #Kubernetes #Terraform #Docker #AmazonECR #AWSIAM #OIDC #DevSecOps #InfrastructureAsCode #CloudComputing #AWSCommunity #LearningInPublic
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article