-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
631b97f
commit fe729c6
Showing
72 changed files
with
1,775 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
content/amazon-ec2-spot-cicd-workshop/gitlab-spot/_index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
title: "CI/CD and Test Workloads (GitLab) with EC2 Spot Instances" | ||
menuTitle: "GitLab" | ||
weight: 20 | ||
pre: "<b></b>" | ||
--- | ||
|
||
## Overview | ||
In this workshop you will add runners on Amazon EC2 Spot instances to a pre-installed GitLab. Then you will build a containerized demo application on them and install it into Kubernetes cluster that also uses only spot instances as its worker nodes. In the end you will test it to verify the results. | ||
|
||
You can perform all workshop steps one-by-one to get to the expected results, but for better understanding of using Spot instances with GitLab we recommend that you also look into the used templates and result files and try modifying them additionally. | ||
|
||
Many workshop steps imply manual actions in the AWS console to better demonstrate the underlying concepts, but in a Production environment it is better to automate them using Infrastructure as Code (IaC), such as [AWS CloudFormation](https://aws.amazon.com/cloudformation/) and [AWS CDK](https://docs.aws.amazon.com/cdk/v2/guide/home.html). | ||
|
||
## Workshop Details | ||
This workshop will be broken down into a series of labs that flow on from each other (that is, you must complete each lab in order before proceeding with the next). The lab exercises that will be covered are: | ||
|
||
* [Starting the workshop](gitlab-spot/before.html) where you will log in to AWS accounts and deploy GitLab, if it is not yet deployed | ||
* [Workshop Preparation](gitlab-spot/prep.html) where you will save GitLab access details and create an AWS Cloud9 environment to execute the workshop steps | ||
* [Lab 1: Create a GitLab repository](gitlab-spot/lab1.html) where you will create a repository in GitLab CI/CD and create a demo application. | ||
* [Lab 2: Configure GitLab runners on Spot instances](gitlab-spot/lab2.html) where you will deploy the GitLab Runners in an auto-scaling group on spot instances | ||
* [Lab 3: Building the demo app](gitlab-spot/lab3.html) where you will push the changes and make sure that your pipeline executes successfully. | ||
* [Lab 4: Deploying Amazon EKS on Spot instances](gitlab-spot/lab4.html) where you will create a new Kubernetes cluster in Amazon EKS that will only have worker nodes on spot instances | ||
* [Lab 5: Installing the demo app into Amazon EKS](gitlab-spot/lab5.html) where you will modify your GitLab CI/CD scripts to add a stage of deploying on Amazon EKS and test the result | ||
* [Workshop Cleanup](gitlab-spot/cleanup.html) where you will remove all the resources created during the workshop |
11 changes: 11 additions & 0 deletions
11
content/amazon-ec2-spot-cicd-workshop/gitlab-spot/before/_index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
+++ | ||
title = "Starting the workshop" | ||
chapter = false | ||
weight = 10 | ||
+++ | ||
|
||
To start the workshop, follow one of the following pages, depending on whether you are... | ||
|
||
{{% children %}} | ||
|
||
Once you are done with either setup, continue with [**Workshop Preparation**](prep.html). |
48 changes: 48 additions & 0 deletions
48
content/amazon-ec2-spot-cicd-workshop/gitlab-spot/before/aws_event.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
+++ | ||
title = "...At an AWS event" | ||
weight = 10 | ||
+++ | ||
|
||
{{% notice warning %}} | ||
Only complete this section if you are at an AWS hosted event (such as re:Invent, public workshop, Immersion Day, or any other event hosted by an AWS employee). If you are running the workshop on your own, go to: [Start the workshop on your own]({{< ref "/amazon-ec2-spot-cicd-workshop/gitlab-spot/before/self_paced.md" >}}) | ||
{{% /notice %}} | ||
|
||
### Login to the AWS Workshop Portal | ||
|
||
If you are at an AWS event, an AWS account created for you to use throughout the workshop. You will need the **Participant Hash** provided to you by the event's organizers. | ||
|
||
1. Connect to the portal by browsing to [https://dashboard.eventengine.run/](https://dashboard.eventengine.run/). | ||
2. Enter the Hash in the text box, and click **Accept Terms & Login** . | ||
3. Select one of the options to sign-in, for example **Email One-Time Password (OTP)** which would request you to type your e-mail address and enter a passcode that you receive. | ||
|
||
![Event Engine Screenshot: Sign in with](/images/gitlab-spot/EE-SignInMethod.png) | ||
|
||
### Get the SSH key and log in to AWS Console | ||
|
||
1. In the Team Dashboard screen, choose **SSH Key**. | ||
2. In the popup page, choose **Download Key**. You will only need it if you decide to do an optional task of configuring runners using Docker Machine (this had been the only way before Auto-Scaling Groups support was added). | ||
|
||
![Event Engine Screenshot: SSH Key](/images/gitlab-spot/EE-SSHKey.png) | ||
|
||
3. Close the popup and back in the Team Dashboard screen, choose **AWS Console**. | ||
4. In the popup page, choose **Open AWS Console**. | ||
5. Select the AWS region specified by your facilitator. | ||
|
||
You are now logged in to the AWS console in an account that was created for you, and will be available only throughout the workshop run time. | ||
|
||
### Open the pre-provisioned CloudFormation stack | ||
|
||
In the next section we will get the login details of the GitLab environment that was pre-provisioned for you via AWS CloudFormation. First, you need to find and open the CloudFormation stack: it is the only one in the account. | ||
|
||
{{%expand "Click to reveal detailed instructions" %}} | ||
1. In the AWS Console enter **CloudFormation** in the search box at the top of the screen and open the service: | ||
|
||
![AWS Console Screenshot: Search for CloudFormation](/images/gitlab-spot/AWSConsole-CloudFormationSearch.png) | ||
|
||
2. In the navigation pane on the left choose **Stacks**. | ||
3. You should see exactly one stack in the list (with the name like `mod-...`), click on it. | ||
{{% /expand%}} | ||
|
||
If there is no CloudFormation stack present, provision it as specified in the section [**...On your own**](self_paced.html). | ||
|
||
You can now proceed to the [**Workshop Preparation**](/amazon-ec2-spot-cicd-workshop/gitlab-spot/prep.html) where you will save the required output values from the stack. |
43 changes: 43 additions & 0 deletions
43
content/amazon-ec2-spot-cicd-workshop/gitlab-spot/before/self_paced.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
+++ | ||
title = "...On your own" | ||
weight = 20 | ||
+++ | ||
|
||
{{% notice warning %}} | ||
Only complete this section if you are running the workshop on your own or if you do not have a CloudFormation stack with GitLab available. If you are at an AWS hosted event (such as re:Invent, public workshop, Immersion Day, or any other event hosted by an AWS employee), go to [Start the workshop at an AWS event]({{< ref "/amazon-ec2-spot-cicd-workshop/gitlab-spot/before/aws_event.md" >}}). | ||
{{% /notice %}} | ||
|
||
### Preparation | ||
|
||
{{% notice warning %}} | ||
Your account must have the ability to create new IAM roles and scope other IAM permissions. | ||
{{% /notice %}} | ||
|
||
1. If you don't already have an AWS account with Administrator access: [create one now by clicking here](https://aws.amazon.com/getting-started/) | ||
2. Log in to [AWS Console](https://console.aws.amazon.com/) with an IAM user having administrator permissions. | ||
3. Download the CloudFormation YAML-template from [this link](https://raw.githubusercontent.com/awslabs/ec2-spot-workshops/master/workshops/amazon-ec2-spot-cicd-workshop/gitlab-spot/gitlab-deploy.yml). | ||
|
||
### Create an SSH key | ||
|
||
You will need an SSH key if you decide to do an optional task of configuring runners using Docker Machine (this had been the only way before Auto-Scaling Groups support was added). The following steps show how to create it. | ||
|
||
1. Open **EC2** service in the AWS Console. | ||
2. In the navigation pane choose **Key Pairs** in the **Network & Security** section. | ||
3. If there is already an existing SSH key and you have its private key, remember its name, otherwise create a new one: | ||
* Choose **Create key pair** | ||
* In the **Name** field enter `ee-default-key-pair` | ||
* In the **Private key file format** list select `.pem` (even if you use Microsoft Windows: we will be uploading this key into an AWS Cloud9 environment) | ||
* Choose **Create key pair** | ||
* Save the .pem file as suggested by your browser | ||
|
||
### Deploy GitLab | ||
Now you will deploy a GitLab instance without any runners. As it is not the purpose of this workshop to dive deep into GitLab itself, the deployment will be fully automated using Infrastructure as Code template in AWS CloudFormation. It will deploy a VPC with two public subnets, an Amazon S3 bucket that you can configure as GitLab cache, an EC2 instance with GitLab itself, an Application Load Balancer and an Amazon CloudFront distribution to organize a secure access to it, an Amazon ECR repository for storing the container image, and a number of supplementary resources. | ||
|
||
1. Open **CloudFormation** service in the AWS Console. | ||
2. In the navigation pane choose **Stacks**. | ||
3. Choose **Create stack** and in the dropdown choose **With new resources (standard)**. | ||
4. In the **Template source** field select **Upload a template file**, choose the file you saved in the [**Preparation**](#preparation) section above, and choose **Next**. | ||
5. In the **Stack name** field enter `mod-gitlab-spot-workshop`, in the **SSHKeyName** field select `ee-default-key-pair` or the name of the key you used in the steps above, and choose **Next**. | ||
6. Choose **Next**. | ||
7. Mark the checkbox **I acknowledge that AWS CloudFormation might create IAM resources.** and choose **Create stack**. | ||
8. Wait until the stack is in `CREATE_COMPLETE` status (it should take approximately 15 minutes) and continue with [**Workshop Preparation**](/amazon-ec2-spot-cicd-workshop/gitlab-spot/prep.html). |
36 changes: 36 additions & 0 deletions
36
content/amazon-ec2-spot-cicd-workshop/gitlab-spot/cleanup.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
+++ | ||
title = "Workshop Cleanup" | ||
weight = 60 | ||
+++ | ||
|
||
You will now remove the resources created during the workshop. | ||
|
||
1. Return to the browser tab with Cloud9 and perform the following commands in the terminal to remove the Kubernetes ingress, service, and deployment: | ||
|
||
``` | ||
kubectl delete ingress/spot-demo | ||
kubectl delete service/spot-demo | ||
kubectl delete deployment/spot-demo | ||
``` | ||
|
||
2. Perform the following commands to remove the Amazon EKS cluster (when asked, use the same parameter values as when you were creating it: Kubernetes version and the VPC ID): | ||
|
||
``` | ||
cd ~/environment/amazon-ec2-spot-cicd-workshop/gitlab-spot/eks-cluster | ||
TOKEN=$(curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 600") | ||
export TF_VAR_aws_region=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/placement/region) | ||
export TF_VAR_alb_policy=$(aws iam get-policy --policy-arn arn:aws:iam::$(aws sts get-caller-identity --output text --query Account):policy/AWSLoadBalancerControllerIAMPolicy --query Policy.Arn --output text) | ||
terraform destroy | ||
``` | ||
|
||
3. When asked if you want to destroy all resources, type `yes` and press Enter. After that, you can close your Cloud9 environment. | ||
4. Depending on how you deployed the runners, do one of the following: | ||
- If you deployed runners using Auto-Scaling Group, in CloudFormation console delete the stack `linux-docker-scaling-spotonly` (the NESTED stack will be removed automatically). | ||
- If you performed the optional steps to deploy runners using Docker Machine, terminate all runner instances in the EC2 console (name starts with `runner-`) if they have not been yet terminated automatically. Also, terminate the instace `GitLabRunnerManager`. Finally, in the EC2 console choose **Security Groups** in the navigation pane and delete the security groups `GitLabRunner` first and then `GitLabRunnerManager`. | ||
5. In Cloud9 console remove the environment you created. | ||
6. In the IAM console remove all roles you created (`gitlab-spot-workshop-admin` and `GitLabRunner`) and all policies (`EKS-ReadAll`, `AWSLoadBalancerControllerIAMPolicy`, unless you had it before the workshop, and, if you did the Docker Run lab, `IAM-PassRole`). | ||
7. In the ECR console open the repository and remove all images inside it (you do not need to remove the repository itself: it will be done automatically when removing the GitLab stack). | ||
8. If you created the GitLab stack in CloudFormation yourself, remove it too (if you used the one created automatically, you will not be able to delete it, so you can leave it as is). | ||
|
||
### Thank you | ||
At this point, we would like to thank you for attending this workshop. |
8 changes: 8 additions & 0 deletions
8
content/amazon-ec2-spot-cicd-workshop/gitlab-spot/cloud9/ap-southeast-1.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
title: "Singapore" | ||
chapter: false | ||
disableToc: true | ||
hidden: true | ||
--- | ||
|
||
Create a Cloud9 Environment: [https://ap-southeast-1.console.aws.amazon.com/cloud9/home?region=ap-southeast-1](https://ap-southeast-1.console.aws.amazon.com/cloud9/home?region=ap-southeast-1) |
8 changes: 8 additions & 0 deletions
8
content/amazon-ec2-spot-cicd-workshop/gitlab-spot/cloud9/eu-central-1.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
title: "Frankfurt" | ||
chapter: false | ||
disableToc: true | ||
hidden: true | ||
--- | ||
|
||
Create a Cloud9 Environment: [https://eu-central-1.console.aws.amazon.com/cloud9/home?region=eu-central-1](https://eu-central-1.console.aws.amazon.com/cloud9/home?region=eu-central-1) |
8 changes: 8 additions & 0 deletions
8
content/amazon-ec2-spot-cicd-workshop/gitlab-spot/cloud9/eu-west-1.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
title: "Ireland" | ||
chapter: false | ||
disableToc: true | ||
hidden: true | ||
--- | ||
|
||
Create a Cloud9 Environment: [https://eu-west-1.console.aws.amazon.com/cloud9/home?region=eu-west-1](https://eu-west-1.console.aws.amazon.com/cloud9/home?region=eu-west-1) |
8 changes: 8 additions & 0 deletions
8
content/amazon-ec2-spot-cicd-workshop/gitlab-spot/cloud9/us-east-1.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
title: "N.Virginia" | ||
chapter: false | ||
disableToc: true | ||
hidden: true | ||
--- | ||
|
||
Create a Cloud9 Environment: [https://us-east-1.console.aws.amazon.com/cloud9/home?region=us-east-1](https://us-east-1.console.aws.amazon.com/cloud9/home?region=us-east-1) |
8 changes: 8 additions & 0 deletions
8
content/amazon-ec2-spot-cicd-workshop/gitlab-spot/cloud9/us-east-2.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
title: "Ohio" | ||
chapter: false | ||
disableToc: true | ||
hidden: true | ||
--- | ||
|
||
Create a Cloud9 Environment: [https://us-east-2.console.aws.amazon.com/cloud9/home?region=us-east-2](https://us-east-2.console.aws.amazon.com/cloud9/home?region=us-east-2) |
8 changes: 8 additions & 0 deletions
8
content/amazon-ec2-spot-cicd-workshop/gitlab-spot/cloud9/us-west-2.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
title: "Oregon" | ||
chapter: false | ||
disableToc: true | ||
hidden: true | ||
--- | ||
|
||
Create a Cloud9 Environment: [https://us-west-2.console.aws.amazon.com/cloud9/home?region=us-west-2](https://us-west-2.console.aws.amazon.com/cloud9/home?region=us-west-2) |
Oops, something went wrong.