Skip to content

Commit 5d37679

Browse files
committed
Welcome to Stack Simplify
1 parent d48915c commit 5d37679

File tree

491 files changed

+21476
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

491 files changed

+21476
-0
lines changed

11-NEW-DevOps-with-AWS-Developer-Tools-and-GitHub/README.md

Lines changed: 683 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: aws-auth
5+
namespace: kube-system
6+
data:
7+
mapRoles: |
8+
- rolearn: arn:aws:iam::180789647333:role/eksctl-eksdemo1-nodegroup-eksdemo1-NodeInstanceRole-Soe7cmvG8sdT
9+
username: system:node:{{EC2PrivateDNSName}}
10+
groups:
11+
- system:bootstrappers
12+
- system:nodes
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
apiVersion: v1
2+
data:
3+
mapRoles: |
4+
- rolearn: arn:aws:iam::180789647333:role/EksCodeBuildKubectlRole
5+
username: build
6+
groups:
7+
- system:masters
8+
- rolearn: arn:aws:iam::180789647333:role/eksctl-eksdemo1-nodegroup-eksdemo1-NodeInstanceRole-Soe7cmvG8sdT
9+
username: system:node:{{EC2PrivateDNSName}}
10+
groups:
11+
- system:bootstrappers
12+
- system:nodes
13+
kind: ConfigMap
14+
metadata:
15+
annotations:
16+
kubectl.kubernetes.io/last-applied-configuration: |
17+
{"apiVersion":"v1","data":{"mapRoles":"- rolearn: arn:aws:iam::180789647333:role/eksctl-eksdemo1-nodegroup-eksdemo1-NodeInstanceRole-Soe7cmvG8sdT\n username: system:node:{{EC2PrivateDNSName}}\n groups:\n - system:bootstrappers\n - system:nodes\n"},"kind":"ConfigMap","metadata":{"annotations":{},"name":"aws-auth","namespace":"kube-system"}}
18+
creationTimestamp: "2025-05-10T10:59:51Z"
19+
name: aws-auth
20+
namespace: kube-system
21+
resourceVersion: "1061745"
22+
uid: fb75795c-4038-4fec-806d-3a0e805869dc
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
FROM nginx
2+
COPY app1 /usr/share/nginx/html/app1
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body style="background-color:rgb(228, 250, 210);">
4+
<h1>Welcome to Stack Simplify - App Version - V1 </h1>
5+
<h3> DevOps for EKS with AWS Developer Tools</h3>
6+
<p>Application Name: App1</p>
7+
</body>
8+
</html>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# buildspec-build.yml
2+
3+
version: 0.2
4+
5+
# Environment variables and values used across phases
6+
env:
7+
variables:
8+
# ECR URI where Docker image will be pushed
9+
IMAGE_URI: "180789647333.dkr.ecr.us-east-1.amazonaws.com/eks-devops"
10+
exported-variables:
11+
# Variables that will be shared with downstream phases or pipelines
12+
- IMAGE_URI
13+
- IMAGE_TAG
14+
15+
phases:
16+
install:
17+
commands:
18+
# Install phase (empty here since the CodeBuild image has necessary tools)
19+
- echo "Install Phase - Nothing to do using latest Amazon Linux Docker Image"
20+
21+
pre_build:
22+
commands:
23+
# Generate a short Docker image tag using GitHub commit SHA (7 characters)
24+
- IMAGE_TAG="$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c1-7)"
25+
- export IMAGE_TAG
26+
# Authenticate Docker with ECR using AWS CLI
27+
- echo "Logging into Amazon ECR at $IMAGE_URI..."
28+
- aws ecr get-login-password | docker login --username AWS --password-stdin $IMAGE_URI
29+
30+
build:
31+
commands:
32+
# Build Docker image using Dockerfile in root directory
33+
- echo "Building Docker image..."
34+
- docker build -t $IMAGE_URI:$IMAGE_TAG .
35+
36+
post_build:
37+
commands:
38+
# Push the built Docker image to ECR repository
39+
- echo "Pushing Docker image to ECR..."
40+
- docker push $IMAGE_URI:$IMAGE_TAG
41+
# Export image metadata to be used in the deploy stage
42+
- echo "Exporting variables for downstream stages..."
43+
- echo "IMAGE_URI=$IMAGE_URI" >> $CODEBUILD_SRC_DIR/exported-vars.env
44+
- echo "IMAGE_TAG=$IMAGE_TAG" >> $CODEBUILD_SRC_DIR/exported-vars.env
45+
46+
# Files that will be included as artifacts for the next stage
47+
artifacts:
48+
files:
49+
- exported-vars.env
50+
- buildspec-deploy.yml
51+
- '**/kube-manifests/**/*'
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# buildspec-deploy.yml
2+
3+
version: 0.2
4+
5+
# Environment variables required for EKS authentication
6+
env:
7+
variables:
8+
# Name of the EKS cluster
9+
EKS_CLUSTER_NAME: "eksdemo1"
10+
# IAM Role ARN used to assume access to EKS for kubectl
11+
EKS_KUBECTL_ROLE_ARN: "arn:aws:iam::180789647333:role/EksCodeBuildKubectlRole"
12+
13+
phases:
14+
install:
15+
commands:
16+
# Install dependencies/tools (if any)
17+
- echo "Install Phase - Installing tools and dependencies"
18+
19+
pre_build:
20+
commands:
21+
# Print info about environment setup
22+
- echo "Setting up IMAGE_URI and IMAGE_TAG from previous stage..."
23+
# List files to verify presence of artifacts
24+
- echo "Listing all files in workspace for debugging:"
25+
- ls -R .
26+
# Source exported variables (IMAGE_URI and IMAGE_TAG)
27+
- echo "Sourcing env variables from file"
28+
- source ./exported-vars.env
29+
- echo "IMAGE_URI=$IMAGE_URI"
30+
- echo "IMAGE_TAG=$IMAGE_TAG"
31+
# Replace placeholder in Kubernetes YAML with actual image URI and tag
32+
- echo "Updating container image in the Kubernetes Deployment YAML file..."
33+
- sed -i 's@CONTAINER_IMAGE@'"$IMAGE_URI:$IMAGE_TAG"'@' kube-manifests/01-DEVOPS-Nginx-Deployment.yml
34+
- echo "Updated deployment manifest content:"
35+
- cat kube-manifests/01-DEVOPS-Nginx-Deployment.yml
36+
37+
build:
38+
commands:
39+
# Assume IAM role to gain temporary credentials for kubectl access
40+
- echo "Assuming IAM Role to access EKS cluster..."
41+
- CREDENTIALS=$(aws sts assume-role --role-arn $EKS_KUBECTL_ROLE_ARN --role-session-name codebuild-kubectl --duration-seconds 900)
42+
- export AWS_ACCESS_KEY_ID=$(echo $CREDENTIALS | jq -r '.Credentials.AccessKeyId')
43+
- export AWS_SECRET_ACCESS_KEY=$(echo $CREDENTIALS | jq -r '.Credentials.SecretAccessKey')
44+
- export AWS_SESSION_TOKEN=$(echo $CREDENTIALS | jq -r '.Credentials.SessionToken')
45+
# Setup kubeconfig to interact with the EKS cluster
46+
- echo "Updating kubeconfig with EKS cluster credentials..."
47+
- aws eks update-kubeconfig --name $EKS_CLUSTER_NAME
48+
# Deploy application manifests to EKS
49+
- echo "Applying Kubernetes manifests..."
50+
- kubectl apply -f kube-manifests/
51+
# Wait for deployment rollout to complete
52+
- echo "Waiting for deployment rollout to complete..."
53+
- kubectl rollout status deployment/eks-devops-deployment --timeout=180s
54+
55+
post_build:
56+
commands:
57+
# Verification steps to ensure everything is deployed correctly
58+
- echo "Verifying Kubernetes resources created:"
59+
- echo "Pods Status:"
60+
- kubectl get pods -o wide
61+
- echo "Services Status:"
62+
- kubectl get svc -o wide
63+
- echo "Ingress Status:"
64+
- kubectl get ingress -o wide
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: eks-devops-deployment
5+
labels:
6+
app: eks-devops
7+
spec:
8+
replicas: 2
9+
selector:
10+
matchLabels:
11+
app: eks-devops
12+
template:
13+
metadata:
14+
labels:
15+
app: eks-devops
16+
spec:
17+
containers:
18+
- name: eks-devops
19+
image: CONTAINER_IMAGE
20+
ports:
21+
- containerPort: 80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: eks-devops-nodeport-service
5+
labels:
6+
app: eks-devops
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: /app1/index.html
10+
spec:
11+
type: NodePort
12+
selector:
13+
app: eks-devops
14+
ports:
15+
- port: 80
16+
targetPort: 80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Annotations Reference: https://kubernetes-sigs.github.io/aws-load-balancer-controller/latest/guide/ingress/annotations/
2+
apiVersion: networking.k8s.io/v1
3+
kind: Ingress
4+
metadata:
5+
name: ingress-externaldns-demo
6+
annotations:
7+
# Load Balancer Name
8+
alb.ingress.kubernetes.io/load-balancer-name: externaldns-ingress
9+
# Ingress Core Settings
10+
alb.ingress.kubernetes.io/scheme: internet-facing
11+
# Health Check Settings
12+
alb.ingress.kubernetes.io/healthcheck-protocol: HTTP
13+
alb.ingress.kubernetes.io/healthcheck-port: traffic-port
14+
#Important Note: Need to add health check path annotations in service level if we are planning to use multiple targets in a load balancer
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/895af13a-cdd1-48ca-b399-2b91da0bdc01
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/ssl-redirect: '443'
26+
# External DNS - For creating a Record Set in Route53
27+
external-dns.alpha.kubernetes.io/hostname: myapp1.stacksimplify.com
28+
spec:
29+
ingressClassName: my-aws-ingress-class # Ingress Class
30+
defaultBackend:
31+
service:
32+
name: eks-devops-nodeport-service
33+
port:
34+
number: 80
35+
36+
# 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.
37+
# 1. If "spec.ingressClassName: my-aws-ingress-class" not specified, will reference default ingress class on this kubernetes cluster
38+
# 2. Default Ingress class is nothing but for which ingress class we have the annotation `ingressclass.kubernetes.io/is-default-class: "true"`
39+
40+

0 commit comments

Comments
 (0)