Skip to content

Commit 89658e9

Browse files
author
Sandip Das
committed
new changes for eks ci/cd
1 parent c040c23 commit 89658e9

Some content is hidden

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

51 files changed

+5729
-46
lines changed

.DS_Store

0 Bytes
Binary file not shown.

Dockerfile

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,7 @@
1-
FROM node:14
2-
3-
RUN apt-get update
4-
5-
# for https
6-
RUN apt-get install -yyq ca-certificates
7-
8-
# install libraries
9-
RUN apt-get install -yyq libappindicator1 libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6
10-
11-
# tools
12-
RUN apt-get install -yyq gconf-service lsb-release wget xdg-utils
13-
14-
# and fonts
15-
RUN apt-get install -yyq fonts-liberation
16-
17-
# RUN npm install yarn -g
1+
FROM 120717539064.dkr.ecr.us-west-2.amazonaws.com/node:14
182

193
# Setting working directory. All the path will be relative to WORKDIR
204
WORKDIR /usr/src/app
21-
# Installing dependencies
22-
RUN npm install typescript -g
23-
RUN mkdir modules && cd modules && mkdir api && mkdir app && mkdir bull && mkdir creatives && mkdir domain && mkdir gcp
24-
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install xorg xvfb gtk2-engines-pixbuf --no-install-recommends
25-
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install dbus-x11 xfonts-base xfonts-100dpi xfonts-75dpi xfonts-cyrillic xfonts-scalable --no-install-recommends
26-
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install imagemagick x11-apps --no-install-recommends
27-
# Install x11vnc.
28-
RUN apt-get install -y x11vnc
29-
# Install xvfb.
30-
RUN apt-get install -y xvfb
31-
# Install fluxbox.
32-
RUN apt-get install -y fluxbox
33-
# Install wget.
34-
RUN apt-get install -y wget
35-
# Install wmctrl.
36-
RUN apt-get install -y wmctrl
37-
# Set the Chrome repo.
38-
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
39-
&& echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list
40-
# Install Chrome.
41-
RUN apt-get update && apt-get -y install google-chrome-stable
42-
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install gconf-service libasound2 libatk1.0-0 libatk-bridge2.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget
43-
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y libgbm-dev
44-
ENV CHROMIUM_FLAGS=--enable-gpu-rasterization,--enable-hardware-overlays,--enforce-vulkan-protected-memory,--use-vulkan
45-
ENV USE_GL=desktop
46-
RUN Xvfb xvfb :1 & Xvfb :10 -ac & export DISPLAY=:10
47-
RUN DEBIAN_FRONTEND=noninteractive apt-get install xserver-xorg-core -y
48-
RUN apt-get install neofetch -y
495

506
# Install app dependencies
517
# A wildcard is used to ensure both package.json AND package-lock.json are copied

buildspec_eks.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
version: 0.2
2+
run-as: root
3+
4+
phases:
5+
6+
install:
7+
commands:
8+
- echo Installing app dependencies...
9+
- curl -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.18.9/2020-11-02/bin/linux/amd64/kubectl
10+
- chmod +x ./kubectl
11+
- mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$PATH:$HOME/bin
12+
- echo 'export PATH=$PATH:$HOME/bin' >> ~/.bashrc
13+
- source ~/.bashrc
14+
- echo 'Check kubectl version'
15+
- kubectl version --short --client
16+
17+
pre_build:
18+
commands:
19+
- echo Logging in to Amazon EKS...
20+
- aws eks --region $AWS_DEFAULT_REGION update-kubeconfig --name $AWS_CLUSTER_NAME
21+
- echo Logging in to Amazon ECR...
22+
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
23+
- REPOSITORY_URI=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME
24+
- docker pull $REPOSITORY_URI:$IMAGE_TAG
25+
26+
27+
build:
28+
commands:
29+
- echo Build started on `date`
30+
- echo Building the Docker image...
31+
- docker build --cache-from $REPOSITORY_URI:$IMAGE_TAG -t $IMAGE_REPO_NAME:$IMAGE_TAG .
32+
- docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
33+
34+
post_build:
35+
commands:
36+
- echo Build completed on `date`
37+
- echo Pushing the Docker image...
38+
- docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
39+
- echo Push the latest image to cluster
40+
- kubectl apply -f k8s/deployment/deployment.yaml
41+
- kubectl rollout restart -f k8s/deployment/deployment.yaml

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('cicd v3!')
8+
res.send('Sample App V2!')
99
})
1010

1111
app.get('/status', (req, res) => {
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# 1.2 Configuring an EKS Cluster
2+
3+
- Create the EKS service role
4+
- Create the VPC infrastructure using CloudFormation
5+
- Create a cluster in the AWS Management Console
6+
- Configure kubectl for EKS
7+
- Configure aws-iam-authenticator
8+
- Launch EKS worker nodes
9+
- Deploy the Kubernetes dashboard
10+
11+
## Amazon EKS Prerequisites
12+
13+
Before you can create an Amazon EKS cluster, you must create an IAM role that Kubernetes can assume to create AWS resources. For example, when a load balancer is created, Kubernetes assumes the role to create an Elastic Load Balancing load balancer in your account. This only needs to be done one time and can be used for multiple EKS clusters.
14+
15+
You must also create a VPC and a security group for your cluster to use. Although the VPC and security groups can be used for multiple EKS clusters, we recommend that you use a separate VPC for each EKS cluster to provide better network isolation.
16+
17+
## Create EKS Service Role
18+
19+
### Create the EKS service role in the IAM console
20+
21+
1. Open the IAM console at [https://console\.aws\.amazon\.com/iam/](https://console.aws.amazon.com/iam/)\.
22+
23+
1. Choose **Roles**, then **Create role**\.
24+
25+
1. Choose **EKS** from the list of services, then **Allows Amazon EKS to manage your clusters on your behalf** for your use case, then **Next: Permissions**\.
26+
27+
1. Choose **Next: Review**\.
28+
29+
1. For **Role name**, enter a unique name for your role, such as `eksServiceRole`, then choose **Create role**\.
30+
31+
## Create EKS Cluster VPC
32+
33+
Specify this S3 template URL in CloudFormation:
34+
35+
`https://amazon-eks.s3-us-west-2.amazonaws.com/cloudformation/2018-11-07/amazon-eks-vpc-sample.yaml`
36+
37+
This is also available from the [EKS Getting Started Guide](https://docs.aws.amazon.com/eks/latest/userguide/getting-started.html#vpc-create)
38+
39+
Note the `SecurityGroups`, `VpcId`, and `SubnetIds` output values.
40+
41+
## Create EKS Cluster
42+
43+
Use AWS Management Console, supplying values from the CloudFormation output in the previous step.
44+
45+
The Security group should be the one containing `ControlPlaneSecurityGroup` in the name.
46+
47+
**Note:** Be sure to create the EKS Cluster using the same IAM user or role that you intend to manage that cluster with from the CLI.
48+
49+
This step can take several minutes to complete.
50+
51+
## Install kubectl
52+
53+
For example, to install version 1.10.3 on macOS:
54+
55+
```sh
56+
curl -o kubectl https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-07-26/bin/darwin/amd64/kubectl
57+
58+
chmod +x ./kubectl
59+
```
60+
61+
Ensure that `kubectl` is in your `PATH`.
62+
63+
To install on Amazon Linux:
64+
65+
```bash
66+
curl -o kubectl https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-07-26/bin/linux/amd64/kubectl
67+
68+
chmod +x ./kubectl
69+
70+
71+
mkdir $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$HOME/bin:$PATH
72+
73+
echo 'export PATH=$HOME/bin:$PATH' >> ~/.bashrc
74+
```
75+
76+
## Install aws-iam-authenticator
77+
78+
For example, to install version 1.10.3 for macOS:
79+
80+
```sh
81+
curl -o aws-iam-authenticator https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-07-26/bin/darwin/amd64/aws-iam-authenticator
82+
83+
chmod +x ./aws-iam-authenticator
84+
```
85+
86+
Ensure that `aws-iam-authenticator` is in your `PATH`.
87+
88+
## Configure kubectl
89+
90+
`aws eks update-kubeconfig --name <cluster name>`
91+
92+
## Launch Worker Nodes
93+
94+
Wait for the cluster status to show `ACTIVE`.
95+
96+
Create the following CloudFormation stack using this S3 URL:
97+
98+
`https://amazon-eks.s3-us-west-2.amazonaws.com/cloudformation/2018-11-07/amazon-eks-nodegroup.yaml`
99+
100+
Specify the Amazon EKS-optimized AMI ID for your region:
101+
102+
|Region|Amazon EKS-optimized AMI|
103+
|------|------------------------|
104+
|US West (Oregon) (us-west-2)|ami-0f54a2f7d2e9c88b3|
105+
|US East (N. Virginia)(us-east-1)|ami-0a0b913ef3249b655|
106+
|US East (Ohio)(us-east-2)|ami-0958a76db2d150238|
107+
|EU (Ireland)(eu-west-1)|ami-00c3b2d35bddd4f5c|
108+
109+
## Enable Worker Nodes to Join Cluster
110+
111+
Download the configuration map:
112+
113+
`curl -O https://amazon-eks.s3-us-west-2.amazonaws.com/cloudformation/2018-11-07/aws-auth-cm.yaml`
114+
115+
Edit this file, replacing the `<ARN of instance role (not instance profile)> ` snippet with the `NodeInstanceRole` value that you recorded in the previous procedure, and save the file.
116+
117+
Apply the configuration.
118+
119+
`kubectl apply -f aws-auth-cm.yaml`
120+
121+
`kubectl get nodes --watch`
122+
123+
## Deploy the Kubernetes Dashboard
124+
125+
`kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml`
126+
127+
`kubectl proxy &`
128+
129+
Browse to: <http://localhost:8080/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/>
130+
131+
## Get an authentication token
132+
133+
`aws-iam-authenticator token -i <cluster_name> --token-only`
134+
135+
Set this token in the k8s dashboard.

0 commit comments

Comments
 (0)