Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kops #14

Open
wants to merge 33 commits into
base: add-vpc
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1e8a581
Add explicit backend to terraform scripts (#13)
thejsj May 18, 2017
674dbc1
WIP
thejsj Apr 27, 2017
2d65e0b
Add validated changes
thejsj Apr 27, 2017
ca648e2
Remove unsued variables
thejsj Apr 27, 2017
dd8093c
Fix database module
thejsj Apr 27, 2017
10cc7b0
Fix instance module
thejsj Apr 27, 2017
8083298
Start adding bastion
thejsj Apr 27, 2017
d6039e2
Add fixes
thejsj Apr 28, 2017
04bcd09
WIP: Adding VPC, subnets, route tables, etc
thejsj May 1, 2017
030e3cf
Add output and minor fixes
thejsj May 10, 2017
01e47a1
Change public key to file
thejsj May 11, 2017
928bf95
Add route53
thejsj May 11, 2017
58d7fe8
Add Route53 setup
thejsj May 11, 2017
e8797b8
Add new s3 bucket
thejsj May 11, 2017
26398fd
Add output and kops script
thejsj May 11, 2017
76c5ece
Start refactoring
thejsj May 12, 2017
f0ab6a8
WIP Addp K8 stuff
thejsj May 15, 2017
3e2439f
Add main terraform file
thejsj May 18, 2017
db43d0b
Fix setup of kops cluster. Fix Readme
thejsj May 18, 2017
4be7b86
Add security groups from cluster
thejsj May 18, 2017
ba68023
Remove main instance and related resources. Fix kops terraform apply
thejsj May 19, 2017
627ed03
Add default username and password
thejsj May 19, 2017
23007ed
Update README.md
thejsj May 19, 2017
a5e4344
Update bastion and database
thejsj Jun 1, 2017
cfb9204
Update README and cluster creation
thejsj Jun 2, 2017
0145db4
Fix node-count
thejsj Jun 5, 2017
0abf158
Start ASG with 0 instances
thejsj Jun 26, 2017
a8b743b
Ignore back files
thejsj Jun 26, 2017
5634b4c
Fix comments
thejsj Jul 5, 2017
ee8ead3
Change backend to S3. Change desired capacity to 0
thejsj Jul 6, 2017
d3fd612
Create the elastic ip, nat gateway, routing table for docks (#21)
henrymollman Jul 7, 2017
c23cdeb
Output dock subnet cidr range (#22)
henrymollman Jul 13, 2017
722e8c6
Small helpers for readme (#19)
Myztiq Jul 13, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Compiled files
*.tfstate
*.tfstate.backup
*.bak

# Module directory
.terraform/
Expand All @@ -9,3 +10,4 @@
environments/*
!environments/runnable-on-prem.example.tfvars

step-2-kops
105 changes: 102 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,108 @@
# Runnable On-Prem Terraform

### Dependencies

```
brew install terraform kops jq kubectl

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should also provide link to install brew.

```

### Step 1: Obtaining AWS Access Tokens

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


```
# TODO: Define permisisons
export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=
terraform get
terraform plan
terraform apply
```

### Step 2: Populating Variables

Populate `environments/main.tfvars` with correct variables.

The following are the only required variables:

```
# Domain to be used by Runnable.
# Access to setting DNS nameservers is required.
# Multiple subdomains must be set for this domain
domain = "runnable.com"
# A Github organization id (See below of obtainig ID)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/obtainig/obtaining

github_org_id = "2828361" # Github ID for organization
# Location of previously generationg configuation
# Should be generated using github.com/CodeNow/on-prem-devops-scripts
lc_user_data_file_location = "~/dock-runnable-on-prem.sh" # File must be already generated
# Path to a publick key (See below of generating public key)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/publick/public

public_key_path = "~/.ssh/*.pub" # A public key
```

##### Obtaining A Github ID

```
curl -sS "https://api.github.com/orgs/$ORGNAME" | jq '.id'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ORGNAME was not defined anywhere? also stick with one convention in this doc either $ORGNAME or ${ORGNAME}

```

##### Obtaining A Public Key From Private Key

```
ssh-keygen -y -f ~/.ssh/${NAME}.pem >> ~/.ssh/${NAME}.pem.pub
```

### Step 3: Init Terraform and Apply First Part

```
terraform init

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add cd step, or tell me what directory I need to be in to run this command

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're supposed to run it from this directory... cd ./on-prem-terraform?

# Bug in terraform requires explicitely requiring submodules https://github.com/hashicorp/terraform/issues/5190
terraform apply -target=module.step_1.module.key_pair -target=module.step_1.module.vpc -target=module.step_1.module.route53 -target=module.step_1.module.s3 -var-file="environments/main.tfvars"
```

### Step 4: Update DNS

Run `terraform referesh -var-file="environments/main.tfvars"` and update the name servers for your domain. There should 4 entries. DNS nameservers need to be propagated before going on to the next step.

### Step 5: Create Kops configuration

[kops]() is a tool to automatically spin up

```
source create-k8-cluster.bash environments/main.tfvars

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you using source vs bash or sh or just running ./create-k8-cluster.bash

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea. what's the difference?

```

### Step 6: Apply configuration

Finally, it's time to create the infrastructure. This include the kuberentes cluster, the auto scaling group for the dock workers, and the RDS database.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/include/includes


If you with to review the resources to be created, first run `terraform plan -var-file="environments/main.tfvars"`.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/with/want


When you're ready to apply changes, just run

```
terraform apply -var-file="environments/main.tfvars"
```


### Step 7: Confirm Cluster is Up

After finishing the setup, you can now test if the cluster is up by running the following command.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add note: this can take up to 10 minutes


```
kubectl get nodes
```

You should see something like this. It will take some time for nodes to appear as "Ready":

```
$ kubectl get nodes
NAME STATUS AGE VERSION
ip-10-10-34-129.us-west-2.compute.internal Ready,master 1h v1.5.7
ip-10-10-57-73.us-west-2.compute.internal Ready 1h v1.5.7
ip-10-10-61-76.us-west-2.compute.internal Ready 1h v1.5.7
```

### Step 8: Add dashboard

After cluster is ready, run the following command to run the dashboard:

```
kubectl create -f https://raw.githubusercontent.com/kubernetes/kops/master/addons/kubernetes-dashboard/v1.5.0.yaml
```

Then, run `kubectl proxy` and go to [`127.0.0.1:8001/ui/`](http://127.0.0.1:8001/ui) to test it.
30 changes: 30 additions & 0 deletions create-k8-cluster.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

# We need to run a refresh before we can run `terraform output`
terraform refresh -var-file=$1 > /dev/null

JSON=$(terraform output -json)
REGION=$(echo $JSON | jq --raw-output '.aws_region.value')
ENV=$(echo $JSON | jq --raw-output '.environment.value')
VPC_ID=$(echo $JSON | jq --raw-output '.vpc_id.value')
BUCKET_NAME=$(echo $JSON | jq --raw-output '.kops_config_bucket.value')
CLUSTER_NAME=$(echo $JSON | jq --raw-output '.cluster_name.value')
SSH_PUBLIC_KEY_PATH=$(echo $JSON | jq --raw-output '.ssh_public_key_path.value')

echo "Creating cluster in VPC $VPC_ID with name $CLUSTER_NAME"

kops create cluster \
--zones="${REGION}a" \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you add a ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be us-west-2a or us-west-2b (a zone, not a region). I added a arbitrarily.

--name=${CLUSTER_NAME} \
--vpc=${VPC_ID} \
--node-count=4 \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 not 3?

--cloud=aws \
--cloud-labels="Environment=${ENV}" \
--ssh-public-key=${SSH_PUBLIC_KEY_PATH} \
--state=s3://${BUCKET_NAME} \
--node-size=m4.large \
--master-size=m4.large \
--out=./step-2-kops --target=terraform

# Move file in order for it to be a valid module
mv ./step-2-kops/kubernetes.tf ./step-2-kops/main.tf
35 changes: 0 additions & 35 deletions database/main.tf

This file was deleted.

10 changes: 2 additions & 8 deletions environments/runnable-on-prem.example.tfvars
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
# All variables in this document should match
domain = ""
github_org_id = ""
public_key = ""
db_username = "" # Must start with a letter
db_password = ""
db_subnet_group_name = ""
main_host_vpc_id = ""
main_host_subnet_id = ""
main_host_private_ip = "10.4.0.100"
dock_subnet_id = ""
github_org_id = ""
key_name = ""
lc_user_data_file_location = "~/dock-runnable-on-prem.sh"
bastion_sg_id = ""
environment = "runnable-on-prem"
aws_region = "us-west-2"
185 changes: 0 additions & 185 deletions instances-and-security-groups/main.tf

This file was deleted.

Loading