Provisioning a GitLab Instance on an AWS VM
This tutorial provides step-by-step instructions for provisioning a GitLab instance on an AWS EC2 VM using the GitLab Sandbox Cloud.
Prerequisites
Section titled “Prerequisites”- Access to GitLab Sandbox Cloud
- Okta credentials for authentication
- SSH key pair for EC2 instance access (can also be created during EC2 instance launch)
1. Access GitLab Sandbox Cloud
Section titled “1. Access GitLab Sandbox Cloud”- Go to https://gitlabsandbox.cloud/ and login with Okta
- Create an account if you don’t have one with the following settings:
- Cloud provider:
aws-51eab1fa(Master Account) - Organizational Unit:
eng-infra-sandbox
- Cloud provider:
2. Access Your AWS Account
Section titled “2. Access Your AWS Account”When the account has been created (or if you already had one):
- Access it by clicking on your account in the Sandbox Cloud dashboard
- Use the Open AWS Web Console button in your Cloud Account page
- Log in to the AWS account using the username and password from View IAM Credentials
3. Launch an EC2 Instance
Section titled “3. Launch an EC2 Instance”- Go to EC2 in the AWS Console
- Click Launch instance
- Configure the instance:
- Give it a name
- Select Ubuntu as the AMI
- Select instance type t2.medium or larger (GitLab requires a minimum of 4 GB RAM)
- Select or create a key pair. If creating a new key pair, download the
.pemfile immediately — you will need it for SSH access later
- Under Network settings, allow HTTP/HTTPS traffic from the internet
- Configure storage: 50 GiB gp2/gp3 (NOT iops)
- Click the Launch instance button on the right
- Go to your instances to see info about the created instance
4. Install GitLab
Section titled “4. Install GitLab”You can install GitLab using one of two methods:
Option A: Manual Installation
Section titled “Option A: Manual Installation”-
If you created your key pair using the AWS dashboard, update the key file permissions first:
Terminal window chmod 600 <absolute-path-to-ssh-key> -
SSH into the instance:
Terminal window ssh -i <absolute-path-to-ssh-key> ubuntu@<public-dns-of-the-instance> -
Follow the instructions to install GitLab: https://docs.gitlab.com/install/package/ubuntu/
Option B: Using OpenCode (Recommended)
Section titled “Option B: Using OpenCode (Recommended)”Use this prompt with OpenCode:
SSH into
ubuntu@<public-dns-of-the-instance>and install GitLab following https://docs.gitlab.com/install/package/ubuntu/. To SSH into the VM use this key:<absolute-path-to-ssh-key>
Dealing with Machine Restarts
Section titled “Dealing with Machine Restarts”When stopping and starting EC2 instances, a new IP address and hostname is assigned to the instance. You can fix this in one of two ways:
Option 1: Assign an Elastic IP (Recommended for Persistent Use)
Section titled “Option 1: Assign an Elastic IP (Recommended for Persistent Use)”Assign your EC2 instance an Elastic IP to make the IP static.
Note: Elastic IPs may incur additional costs.
Option 2: Update GitLab Configuration
Section titled “Option 2: Update GitLab Configuration”Once the machine is running again:
-
Update the
external_urlparameter in/etc/gitlab/gitlab.rbto point to the new hostname:external_url 'http://<new-public-dns-of-the-instance>' -
Run the following commands:
Terminal window sudo gitlab-ctl reconfiguresudo gitlab-ctl restart -
The instance is now available on the new hostname