Skip to content

Commit 3071879

Browse files
authored
Merge pull request #1 from stacksimplify/master
leatest
2 parents a4c930f + 1148246 commit 3071879

File tree

6 files changed

+219
-16
lines changed

6 files changed

+219
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: kubeapp-ecr
5+
labels:
6+
app: kubeapp-ecr
7+
spec:
8+
replicas: 2
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: 180789647333.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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: kubeapp-ecr-nodeport-service
5+
labels:
6+
app: kubeapp-ecr
7+
annotations:
8+
#Important Note: Need to add health check path annotations in service level if we are planning to use multiple targets in a load balancer
9+
alb.ingress.kubernetes.io/healthcheck-path: /index.html
10+
spec:
11+
type: NodePort
12+
selector:
13+
app: kubeapp-ecr
14+
ports:
15+
- port: 80
16+
targetPort: 80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Annotations Reference: https://kubernetes-sigs.github.io/aws-alb-ingress-controller/guide/ingress/annotation/
2+
apiVersion: extensions/v1beta1
3+
kind: Ingress
4+
metadata:
5+
name: ecr-ingress-service
6+
labels:
7+
app: kubeapp-ecr
8+
annotations:
9+
# Ingress Core Settings
10+
kubernetes.io/ingress.class: "alb"
11+
alb.ingress.kubernetes.io/scheme: internet-facing
12+
# Health Check Settings
13+
alb.ingress.kubernetes.io/healthcheck-protocol: HTTP
14+
alb.ingress.kubernetes.io/healthcheck-port: traffic-port
15+
alb.ingress.kubernetes.io/healthcheck-interval-seconds: '15'
16+
alb.ingress.kubernetes.io/healthcheck-timeout-seconds: '5'
17+
alb.ingress.kubernetes.io/success-codes: '200'
18+
alb.ingress.kubernetes.io/healthy-threshold-count: '2'
19+
alb.ingress.kubernetes.io/unhealthy-threshold-count: '2'
20+
## SSL Settings
21+
alb.ingress.kubernetes.io/listen-ports: '[{"HTTPS":443}, {"HTTP":80}]'
22+
alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:us-east-1:180789647333:certificate/9f042b5d-86fd-4fad-96d0-c81c5abc71e1
23+
#alb.ingress.kubernetes.io/ssl-policy: ELBSecurityPolicy-TLS-1-1-2017-01 #Optional (Picks default if not used)
24+
# SSL Redirect Setting
25+
alb.ingress.kubernetes.io/actions.ssl-redirect: '{"Type": "redirect", "RedirectConfig": { "Protocol": "HTTPS", "Port": "443", "StatusCode": "HTTP_301"}}'
26+
# External DNS - For creating a Record Set in Route53
27+
external-dns.alpha.kubernetes.io/hostname: ecrdemo.kubeoncloud.com
28+
spec:
29+
rules:
30+
- http:
31+
paths:
32+
- path: /* # SSL Redirect Setting
33+
backend:
34+
serviceName: ssl-redirect
35+
servicePort: use-annotation
36+
- path: /*
37+
backend:
38+
serviceName: kubeapp-ecr-nodeport-service
39+
servicePort: 80
40+
# Important Note-1: In path based routing order is very important, if we are going to use "/*", try to use it at the end of all rules.
41+
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,43 @@
1-
# Annotations Reference: https://kubernetes-sigs.github.io/aws-alb-ingress-controller/guide/ingress/annotation/
2-
apiVersion: extensions/v1beta1
1+
# Annotations Reference: https://kubernetes-sigs.github.io/aws-load-balancer-controller/latest/guide/ingress/annotations/
2+
apiVersion: networking.k8s.io/v1
33
kind: Ingress
44
metadata:
55
name: ecr-ingress-service
66
labels:
77
app: kubeapp-ecr
88
annotations:
9+
# Load Balancer Name
10+
alb.ingress.kubernetes.io/load-balancer-name: ecr-ingress
911
# Ingress Core Settings
10-
kubernetes.io/ingress.class: "alb"
12+
#kubernetes.io/ingress.class: "alb" (OLD INGRESS CLASS NOTATION - STILL WORKS BUT RECOMMENDED TO USE IngressClass Resource)
1113
alb.ingress.kubernetes.io/scheme: internet-facing
1214
# Health Check Settings
1315
alb.ingress.kubernetes.io/healthcheck-protocol: HTTP
1416
alb.ingress.kubernetes.io/healthcheck-port: traffic-port
17+
#Important Note: Need to add health check path annotations in service level if we are planning to use multiple targets in a load balancer
1518
alb.ingress.kubernetes.io/healthcheck-interval-seconds: '15'
1619
alb.ingress.kubernetes.io/healthcheck-timeout-seconds: '5'
1720
alb.ingress.kubernetes.io/success-codes: '200'
1821
alb.ingress.kubernetes.io/healthy-threshold-count: '2'
19-
alb.ingress.kubernetes.io/unhealthy-threshold-count: '2'
22+
alb.ingress.kubernetes.io/unhealthy-threshold-count: '2'
2023
## SSL Settings
2124
alb.ingress.kubernetes.io/listen-ports: '[{"HTTPS":443}, {"HTTP":80}]'
22-
alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:us-east-1:180789647333:certificate/9f042b5d-86fd-4fad-96d0-c81c5abc71e1
25+
alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:us-east-1:180789647333:certificate/d86de939-8ffd-410f-adce-0ce1f5be6e0d
2326
#alb.ingress.kubernetes.io/ssl-policy: ELBSecurityPolicy-TLS-1-1-2017-01 #Optional (Picks default if not used)
2427
# SSL Redirect Setting
25-
alb.ingress.kubernetes.io/actions.ssl-redirect: '{"Type": "redirect", "RedirectConfig": { "Protocol": "HTTPS", "Port": "443", "StatusCode": "HTTP_301"}}'
28+
alb.ingress.kubernetes.io/ssl-redirect: '443'
2629
# External DNS - For creating a Record Set in Route53
27-
external-dns.alpha.kubernetes.io/hostname: ecrdemo.kubeoncloud.com
30+
external-dns.alpha.kubernetes.io/hostname: ecrdemo.kubeoncloud.com
2831
spec:
2932
rules:
3033
- http:
31-
paths:
32-
- path: /* # SSL Redirect Setting
34+
paths:
35+
- path: /
36+
pathType: Prefix
3337
backend:
34-
serviceName: ssl-redirect
35-
servicePort: use-annotation
36-
- path: /*
37-
backend:
38-
serviceName: kubeapp-ecr-nodeport-service
39-
servicePort: 80
38+
service:
39+
name: kubeapp-ecr-nodeport-service
40+
port:
41+
number: 80
4042
# Important Note-1: In path based routing order is very important, if we are going to use "/*", try to use it at the end of all rules.
4143

11-DevOps-with-AWS-Developer-Tools/README.md

+117-1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,86 @@ aws iam put-role-policy --role-name EksCodeBuildKubectlRole --policy-name eks-de
109109
# Verify the same on Management Console
110110
```
111111

112+
### For Windows users who are using Powershell
113+
```t
114+
Here is a solutions to creating the Trust policy from AWS Tech Support
115+
116+
I understand that you are following an instruction to create an IAM role for CodeBuild but the commands do not work for PowerShell.
117+
118+
In PowerShell, the format is different from the scripts in Mac OS. Cmdlets are used in PowerShell. I have used Cmdlets in PowerShell to create a role and attach an inline policy. Please check the following for the details:
119+
120+
1. Create IAM Role for CodeBuild to Interact with EKS
121+
122+
First create a new file NewRoleTrustPolicy.json with the following contents:
123+
124+
{
125+
126+
"Version": "2012-10-17",
127+
128+
"Statement": [
129+
130+
{
131+
132+
"Sid": "",
133+
134+
"Effect": "Allow",
135+
136+
"Principal": {
137+
138+
"AWS": "arn:aws:iam::xxxxxxxxxxxx:root"
139+
140+
},
141+
142+
"Action": "sts:AssumeRole"
143+
144+
}
145+
146+
]
147+
148+
}
149+
150+
Note: please replace your account ID in the above Principal parameter.
151+
152+
153+
New-IAMRole -AssumeRolePolicyDocument (Get-Content -raw NewRoleTrustPolicy.json) -RoleName EksCodeBuildKubectlRole
154+
155+
After the above command, you can check if the IAM role EksCodeBuildKubectlRole is created in your AWS account. Please check the New-IAMRole Cmdlet reference in [1].
156+
157+
158+
2. Define Inline Policy with eks Describe permission in a file iam-eks-describe-policy
159+
160+
First create a new file iam-eks-describe-policy.json with the following contents:
161+
162+
{ "Version": "2012-10-17",
163+
164+
"Statement":
165+
166+
[ { "Effect": "Allow",
167+
168+
"Action": "eks:Describe*",
169+
170+
"Resource": "*" }
171+
172+
]
173+
174+
}
175+
176+
Write-IAMRolePolicy -RoleName EksCodeBuildKubectlRole -PolicyName eks-describe -PolicyDocument (Get-Content -Raw iam-eks-describe-policy.json)
177+
178+
179+
After the above command, you can check if the IAM role EksCodeBuildKubectlRole has the inline policy eks-describe attached. Please check the Write-IAMRolePolicy Cmdlet reference in [2].
180+
I hope the above information can help you.
181+
182+
References
183+
================
184+
[1]: New-IAMRole
185+
https://docs.aws.amazon.com/powershell/latest/reference/items/New-IAMRole.html
186+
[2]: Write-IAMRolePolicy
187+
https://docs.aws.amazon.com/powershell/latest/reference/items/Write-IAMRolePolicy.html
188+
189+
190+
```
191+
112192
## Step-07: Update EKS Cluster aws-auth ConfigMap with new role created in previous step
113193
- We are going to add the role to the `aws-auth ConfigMap` for the EKS cluster.
114194
- Once the `EKS aws-auth ConfigMap` includes this new role, kubectl in the CodeBuild stage of the pipeline will be able to interact with the EKS cluster via the IAM role.
@@ -132,6 +212,42 @@ kubectl patch configmap/aws-auth -n kube-system --patch "$(cat /tmp/aws-auth-pat
132212
kubectl get configmap aws-auth -o yaml -n kube-system
133213
```
134214

215+
### This is for the changing the Configmap with Windows PowerShell
216+
```t
217+
This is for the changing the Configmap and PowerShell
218+
219+
In PowerShell, the following steps can be used:
220+
221+
1. kubectl edit -n kube-system configmap/aws-auth
222+
2. In step1, there will be a file opened for you to edit configmap/aws-auth.
223+
In the opened file, there is a mapRoles field such as:
224+
data:
225+
mapRoles: |
226+
- rolearn: <ARN of instance role>
227+
username: system:node:{{EC2PrivateDNSName}}
228+
groups:
229+
- system:bootstrappers
230+
- system:nodes
231+
232+
3. Add the EksCodeBuildKubectlRole information into the mapRoles field of the file such as:
233+
data:
234+
mapRoles: |
235+
- rolearn: arn:aws:iam::018185988195:role/EksCodeBuildKubectlRole
236+
username: build
237+
groups:
238+
- system:masters
239+
- rolearn: <ARN of instance role (not instance profile)>
240+
username: system:node:{{EC2PrivateDNSName}}
241+
groups:
242+
- system:bootstrappers
243+
- system:nodes
244+
245+
Save the file.
246+
247+
248+
4. After the file is saved and closed, configmap/aws-auth has been edited. You can check configmap/aws-auth using the command "kubectl describe -n kube-system configmap/aws-auth".
249+
```
250+
135251
## Step-08: Review the buildspec.yml for CodeBuild & Environment Variables
136252

137253
### Code Build Introduction
@@ -362,4 +478,4 @@ kubectl delete -f kube-manifests/
362478
- https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-available.html
363479
- https://github.com/aws/aws-codebuild-docker-images/blob/master/al2/x86_64/standard/3.0/Dockerfile
364480
- **STS Assume Role:** https://docs.aws.amazon.com/cli/latest/reference/sts/assume-role.html
365-
- https://docs.aws.amazon.com/IAM/latest/UserGuide/troubleshoot_roles.html
481+
- https://docs.aws.amazon.com/IAM/latest/UserGuide/troubleshoot_roles.html
Binary file not shown.

0 commit comments

Comments
 (0)