Skip to content

Commit 09ca438

Browse files
author
Sandip Das
committed
code changes
1 parent af1b3b2 commit 09ca438

File tree

9 files changed

+142
-50
lines changed

9 files changed

+142
-50
lines changed

buildspec_eks.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ phases:
4343
- echo Pushing the Docker image...
4444
- docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
4545
- echo Push the latest image to cluster
46-
- kubectl apply -f k8s/deployment/deployment.yaml
47-
- kubectl rollout restart -f k8s/deployment/deployment.yaml
46+
- kubectl apply -f eks_cicd/deployment.yaml
47+
- kubectl rollout restart -f eks_cicd/deployment.yaml

eks_cicd/cluster.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: eksctl.io/v1alpha5
2+
kind: ClusterConfig
3+
4+
metadata:
5+
name: cicd-demo #cluster name
6+
region: us-west-2 #desired region
7+
8+
nodeGroups:
9+
- name: ng-1 #cluster node group name
10+
instanceType: t2.medium #desired instance type
11+
desiredCapacity: 3 #desired nodes count / capacity
12+
ssh:
13+
allow: false # if true - will use ~/.ssh/id_rsa.pub as the default ssh key
14+
#publicKeyPath: ~/.ssh/ec2_id_rsa.pub #you can specify the public key path likr this as well

eks_cicd/deployment.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
labels:
5+
app.kubernetes.io/name: cicd-demo
6+
app.kubernetes.io/instance: cicd-demo-instance
7+
app.kubernetes.io/version: '1.0.0'
8+
app.kubernetes.io/managed-by: kubectl
9+
name: cicd-demo-deployment
10+
spec:
11+
replicas: 1
12+
selector:
13+
matchLabels:
14+
app: cicd-demo
15+
template:
16+
metadata:
17+
labels:
18+
app: cicd-demo
19+
spec:
20+
containers:
21+
- image: 120717539064.dkr.ecr.us-west-2.amazonaws.com/cicd-demo:latest
22+
imagePullPolicy: Always
23+
name: cicd-demo
24+
ports:
25+
- containerPort: 3000

eks_cicd/prereqs.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env bash
2+
3+
# This script will install EKS prerequisites on Amazon Linux or Amazon Linux 2
4+
# * kubectl
5+
# * aws-iam-authenticator
6+
# * AWS CLI
7+
8+
set -e
9+
10+
mkdir -p $HOME/bin
11+
echo 'export PATH=$HOME/bin:$PATH' >>~/.bashrc
12+
13+
# Install kubectl, if absent
14+
if ! type kubectl >/dev/null 2>&1; then
15+
curl -o "kubectl https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-07-26/bin/$(uname -s)/amd64/kubectl"
16+
chmod +x ./kubectl
17+
cp ./kubectl $HOME/bin/kubectl && export PATH=$HOME/bin:$PATH
18+
echo 'kubectl installed'
19+
else
20+
echo 'kubectl already installed'
21+
fi
22+
23+
# aws-iam-authenticator
24+
if ! type aws-iam-authenticator >/dev/null 2>&1; then
25+
curl -o aws-iam-authenticator "https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-07-26/bin/$(uname -s)/amd64/aws-iam-authenticator"
26+
chmod +x ./aws-iam-authenticator
27+
cp ./aws-iam-authenticator $HOME/bin/aws-iam-authenticator && export PATH=$HOME/bin:$PATH
28+
echo 'aws-iam-authenticator installed'
29+
else
30+
echo 'aws-iam-authenticator already installed'
31+
fi
32+
33+
# AWS CLI
34+
if ! type aws >/dev/null 2>&1; then
35+
curl -o awscli-bundle.zip https://s3.amazonaws.com/aws-cli/awscli-bundle.zip
36+
unzip awscli-bundle.zip
37+
./awscli-bundle/install -b $HOME/bin/aws
38+
echo 'AWS CLI installed'
39+
else
40+
echo 'AWS CLI already installed'
41+
fi
42+
43+
# eksctl
44+
if ! type eksctl >/dev/null 2>&1; then
45+
curl --silent --location "https://github.com/weaveworks/eksctl/releases/download/latest_release/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
46+
mv /tmp/eksctl $HOME/bin
47+
echo 'eksctl installed'
48+
else
49+
echo 'eksctl already installed'
50+
fi
51+
52+
# kubectx/kubens
53+
if ! type kubectx >/dev/null 2>&1; then
54+
git clone https://github.com/ahmetb/kubectx /opt/kubectx
55+
ln -s /opt/kubectx/kubectx /usr/local/bin/kubectx
56+
ln -s /opt/kubectx/kubens /usr/local/bin/kubens
57+
echo 'kubectx installed'
58+
else
59+
echo 'kubectx already installed'
60+
fi
61+
62+
# Test if AWS credentials exist
63+
aws sts get-caller-identity

eks_cicd/service.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
labels:
5+
app.kubernetes.io/name: cicd-demo
6+
app.kubernetes.io/instance: cicd-demo-instance
7+
app.kubernetes.io/version: "1.0.0"
8+
app.kubernetes.io/component: backend
9+
app.kubernetes.io/managed-by: kubectl
10+
name: cicd-demo
11+
spec:
12+
selector:
13+
app: cicd-demo
14+
type: LoadBalancer
15+
ports:
16+
- protocol: TCP
17+
port: 80
18+
targetPort: 3000

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const config = require('config')
55
console.log(config);
66

77
app.get('/', (req, res) => {
8-
res.send('Sample App V2!')
8+
res.send('CICD App V1!')
99
})
1010

1111
app.get('/status', (req, res) => {

k8s/deployment/deployment.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@ apiVersion: apps/v1
22
kind: Deployment
33
metadata:
44
labels:
5-
app.kubernetes.io/name: sample-demo
6-
app.kubernetes.io/instance: sample-demo-instance
5+
app.kubernetes.io/name: cicd-demo
6+
app.kubernetes.io/instance: cicd-demo-instance
77
app.kubernetes.io/version: '1.0.0'
88
app.kubernetes.io/managed-by: kubectl
9-
name: sample-demo-deployment
9+
name: cicd-demo-deployment
1010
spec:
1111
replicas: 1
1212
selector:
1313
matchLabels:
14-
app: sample-demo
14+
app: cicd-demo
1515
template:
1616
metadata:
1717
labels:
18-
app: sample-demo
18+
app: cicd-demo
1919
spec:
2020
containers:
21-
- image: 120717539064.dkr.ecr.us-west-2.amazonaws.com/sample-demo-app:latest
21+
- image: 120717539064.dkr.ecr.us-west-2.amazonaws.com/cicd-demo:latest
2222
imagePullPolicy: Always
23-
name: sample-demo
23+
name: cicd-demo
2424
ports:
2525
- containerPort: 3000

k8s/deployment/service.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ apiVersion: v1
22
kind: Service
33
metadata:
44
labels:
5-
app.kubernetes.io/name: sample-demo
6-
app.kubernetes.io/instance: sample-demo-instance
5+
app.kubernetes.io/name: cicd-demo
6+
app.kubernetes.io/instance: cicd-demo-instance
77
app.kubernetes.io/version: "1.0.0"
88
app.kubernetes.io/component: backend
99
app.kubernetes.io/managed-by: kubectl
10-
name: sample-demo
10+
name: cicd-demo
1111
spec:
1212
selector:
13-
app: sample-demo
13+
app: cicd-demo
1414
type: LoadBalancer
1515
ports:
1616
- protocol: TCP

k8s/rbac/aws-auth.yaml

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,16 @@
11
apiVersion: v1
22
data:
33
mapRoles: |
4-
- rolearn: arn:aws:iam::120717539064:role/service-role/codebuild-samplecicddemo-service-role
4+
- rolearn: arn:aws:iam::120717539064:role/NodeInstanceRole
55
username: system:node:{{EC2PrivateDNSName}}
66
groups:
7-
- system:bootstrappers
8-
- system:nodes
9-
- system:masters
10-
mapUsers: |
11-
[]
7+
- system:bootstrappers
8+
- system:nodes
9+
- rolearn: arn:aws:iam::120717539064:role/codebuild-samplecicddemo-service-role
10+
username: codebuild-samplecicddemo-service-role
11+
groups:
12+
- system:masters
1213
kind: ConfigMap
1314
metadata:
14-
annotations:
15-
kubectl.kubernetes.io/last-applied-configuration: |
16-
{"apiVersion":"v1","data":{"mapRoles":"- rolearn: arn:aws:iam::120717539064:role/service-role/codebuild-samplecicddemo-service-role\n username: system:node:{{EC2PrivateDNSName}}\n groups:\n - system:bootstrappers\n - system:nodes\n"},"kind":"ConfigMap","metadata":{"annotations":{},"name":"aws-auth","namespace":"kube-system"}}
17-
creationTimestamp: "2021-04-25T21:17:41Z"
18-
managedFields:
19-
- apiVersion: v1
20-
fieldsType: FieldsV1
21-
fieldsV1:
22-
f:data:
23-
.: {}
24-
f:mapUsers: {}
25-
manager: eksctl
26-
operation: Update
27-
time: "2021-04-25T21:17:41Z"
28-
- apiVersion: v1
29-
fieldsType: FieldsV1
30-
fieldsV1:
31-
f:data:
32-
f:mapRoles: {}
33-
f:metadata:
34-
f:annotations:
35-
.: {}
36-
f:kubectl.kubernetes.io/last-applied-configuration: {}
37-
manager: kubectl
38-
operation: Update
39-
time: "2021-04-27T04:26:27Z"
4015
name: aws-auth
41-
namespace: kube-system
42-
resourceVersion: "327185"
43-
selfLink: /api/v1/namespaces/kube-system/configmaps/aws-auth
44-
uid: a67fcc4b-f7f8-4796-9c1a-1e5f72ca1657
16+
namespace: kube-system

0 commit comments

Comments
 (0)