Skip to content

Commit d993da0

Browse files
Kalyan Reddy DaidaKalyan Reddy Daida
Kalyan Reddy Daida
authored and
Kalyan Reddy Daida
committed
Welcome to Stack Simplify
1 parent 583f634 commit d993da0

File tree

12 files changed

+222
-1
lines changed

12 files changed

+222
-1
lines changed

03-Kubernetes-Fundamentals/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Kubernetes Fundamentals
2+
- For Kubernetes Fundamentals github repository, please click on below link
3+
- https://github.com/stacksimplify/kubernetes-fundamentals
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM nginx
2+
COPY index.html /usr/share/nginx/html
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body style="background-color:rgb(217, 250, 210);">
4+
5+
<h1>Welcome to Stack Simplify</h1>
6+
<h3>AWS EKS Master Class - Integration with ECR Registry</h3>
7+
8+
</body>
9+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: kubeapp-ecr
5+
labels:
6+
app: backend-restapp
7+
spec:
8+
replicas: 3
9+
selector:
10+
matchLabels:
11+
app: kubeapp-ecr
12+
template:
13+
metadata:
14+
labels:
15+
app: kubeapp-ecr
16+
spec:
17+
containers:
18+
- name: kubeapp-ecr
19+
image: 411686525067.dkr.ecr.us-east-1.amazonaws.com/aws-ecr-kubenginx:1.0.0
20+
resources:
21+
requests:
22+
memory: "128Mi"
23+
cpu: "500m"
24+
limits:
25+
memory: "256Mi"
26+
cpu: "1000m"
27+
ports:
28+
- containerPort: 80
29+
---
30+
apiVersion: v1
31+
kind: Service
32+
metadata:
33+
name: kubeapp-ecr-service
34+
labels:
35+
app: kubeapp-ecr
36+
spec:
37+
type: NodePort
38+
selector:
39+
app: kubeapp-ecr
40+
ports:
41+
- port: 80
42+
targetPort: 80
43+
nodePort: 31031
Original file line numberDiff line numberDiff line change
@@ -1 +1,165 @@
1-
# AWS ECR - Elastic Container Registry Integration with EKS
1+
# AWS ECR - Elastic Container Registry Integration
2+
3+
## Step-01: Introduction to ECR
4+
- For introduction slides refer the [presentation slides](/presentation/AWS-Fargate-and-EKS-Masterclass.pptx).
5+
6+
## Step-02: ECR Terminology
7+
- **Registry:** An ECR registry is provided to each AWS account; we can create image repositories in our registry and store images in them.
8+
- **Repository:** An ECR image repository contains our Docker images.
9+
- **Repository policy:** We can control access to our repositories and the images within them with repository policies.
10+
- **Authorization token:** Our Docker client must authenticate to Amazon ECR registries as an AWS user before it can push and pull images. The AWS CLI get-login command provides us with authentication credentials to pass to Docker.
11+
- **Image:** We can push and pull container images to our repositories. We can use these images locally on your development system, or we can use them in Amazon ECS task definitions.
12+
13+
## Step-03: Pre-requisites
14+
- Install required CLI software on your local desktop
15+
- **Install AWS CLI V2 version**
16+
- We have taken care of this step as part of [01-EKS-Create-Clusters](/01-EKS-Create-Clusters/README.md)
17+
- Documentation Reference: https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html
18+
- **Install Docker CLI**
19+
- We have taken of Docker local desktop installation as part of [Docker Fundamentals](https://github.com/stacksimplify/docker-fundamentals/tree/master/02-Docker-Installation) section
20+
- Docker Desktop for MAC: https://docs.docker.com/docker-for-mac/install/
21+
- Docker Desktop for Windows: https://docs.docker.com/docker-for-windows/install/
22+
- Docker on Linux: https://docs.docker.com/install/linux/docker-ce/centos/
23+
24+
- **On AWS Console**
25+
- We have taken care of this step as part of [01-EKS-Create-Clusters](/01-EKS-Create-Clusters/README.md)
26+
- Create Authorization Token for admin user if not created
27+
- **Configure AWS CLI with Authorization Token**
28+
```
29+
aws configure
30+
AWS Access Key ID: ****
31+
AWS Secret Access Key: ****
32+
Default Region Name: us-east-1
33+
```
34+
35+
## Step-04: Create ECR Repository
36+
- Create simple ECR repository via AWS Console
37+
- Repository Name: aws-ecr-kubenginx
38+
- Tag Immutability: Enable
39+
- Scan on Push: Enable
40+
- Explore ECR console.
41+
- **Create ECR Repository using AWS CLI**
42+
```
43+
aws ecr create-repository --repository-name aws-ecr-kubenginx --region us-east-1
44+
aws ecr create-repository --repository-name <your-repo-name> --region <your-region>
45+
```
46+
47+
## Step-05: Create Docker Image locally
48+
- Navigate to folder **05-ECR-Elastic-Container-Registry\01-aws-ecs-kubenginx** from course github content download.
49+
- Create docker image locally
50+
- Run it locally and test
51+
```
52+
# Build Docker Image
53+
docker build -t <ECR-REPOSITORY-URI>:<TAG> .
54+
docker build -t 180789647333.dkr.ecr.us-east-1.amazonaws.com/aws-ecr-kubenginx:1.0.0 .
55+
56+
# Run Docker Image locally & Test
57+
docker run --name <name-of-container> -p 80:80 --rm -d <ECR-REPOSITORY-URI>:<TAG>
58+
docker run --name aws-ecr-kubenginx -p 80:80 --rm -d 180789647333.dkr.ecr.us-east-1.amazonaws.com/aws-ecr-kubenginx:1.0.0
59+
60+
# Access Application locally
61+
http://localhost
62+
63+
# Stop Docker Container
64+
docker ps
65+
docker stop aws-ecr-kubenginx
66+
docker ps -a -q
67+
68+
# Optional (Delete)
69+
docker build -t 411686525067.dkr.ecr.us-east-1.amazonaws.com/aws-ecr-kubenginx:1.0.0 .
70+
docker run --name aws-ecr-kubenginx -p 80:80 --rm -d 411686525067.dkr.ecr.us-east-1.amazonaws.com/aws-ecr-kubenginx:1.0.0
71+
```
72+
73+
## Step-06: Push Docker Image to AWS ECR
74+
- Firstly, login to ECR Repository
75+
- Push the docker image to ECR
76+
- **AWS CLI Version 2.x**
77+
```
78+
# Get Login Password
79+
aws ecr get-login-password --region <your-region> | docker login --username AWS --password-stdin <ECR-REPOSITORY-URI>
80+
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 180789647333.dkr.ecr.us-east-1.amazonaws.com/aws-ecr-kubenginx
81+
82+
# Push the Docker Image
83+
docker push <ECR-REPOSITORY-URI>:<TAG>
84+
docker push 180789647333.dkr.ecr.us-east-1.amazonaws.com/aws-ecr-kubenginx:1.0.0
85+
86+
# Optional (Delete)
87+
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 411686525067.dkr.ecr.us-east-1.amazonaws.com/aws-ecr-kubenginx
88+
docker push 411686525067.dkr.ecr.us-east-1.amazonaws.com/aws-ecr-kubenginx:1.0.0
89+
```
90+
- Verify the newly pushed docker image on AWS ECR.
91+
- Verify the vulnerability scan results.
92+
93+
## Step-07: Using ECR Image with Amazon EKS
94+
- Understand the Deployment and Service kubernetes manifests present in folder **05-ECR-Elastic-Container-Registry\02-kube-manifests**
95+
- **Important Note:** We have two objects deployment and service present in single yaml file separated by `---`
96+
- Deploy the kubernetes manifests
97+
```
98+
cd 05-ECR-Elastic-Container-Registry\02-kube-manifests
99+
kubectl apply -f ecr-kube-deployment-and-service.yml
100+
kubectl get deploy
101+
kubectl get svc
102+
kubectl get po
103+
```
104+
- Access Application
105+
```
106+
# Get external ip of EKS Cluster Kubernetes worker nodes
107+
kubectl get nodes -o wide
108+
109+
# Access Application
110+
http://<External-IP-of-EKS-Cluster-Nodes>:31031
111+
```
112+
- **ecr-kube-deployment-and-service.yml**
113+
```yml
114+
apiVersion: apps/v1
115+
kind: Deployment
116+
metadata:
117+
name: kubeapp-ecr
118+
labels:
119+
app: backend-restapp
120+
spec:
121+
replicas: 3
122+
selector:
123+
matchLabels:
124+
app: kubeapp-ecr
125+
template:
126+
metadata:
127+
labels:
128+
app: kubeapp-ecr
129+
spec:
130+
containers:
131+
- name: kubeapp-ecr
132+
image: 411686525067.dkr.ecr.us-east-1.amazonaws.com/aws-ecr-kubenginx:1.0.0
133+
resources:
134+
requests:
135+
memory: "128Mi"
136+
cpu: "500m"
137+
limits:
138+
memory: "256Mi"
139+
cpu: "1000m"
140+
ports:
141+
- containerPort: 80
142+
---
143+
apiVersion: v1
144+
kind: Service
145+
metadata:
146+
name: kubeapp-ecr-service
147+
labels:
148+
app: kubeapp-ecr
149+
spec:
150+
type: NodePort
151+
selector:
152+
app: kubeapp-ecr
153+
ports:
154+
- port: 80
155+
targetPort: 80
156+
nodePort: 31031
157+
158+
```
159+
160+
## Step-08: Clean Up
161+
```
162+
cd 05-ECR-Elastic-Container-Registry\02-kube-manifests
163+
kubectl delete -f ecr-kube-deployment-and-service.yml
164+
kubectl get deploy
165+
```
File renamed without changes.
Binary file not shown.

0 commit comments

Comments
 (0)