Skip to content

Commit

Permalink
Merge pull request #10 from vallard/2023-refresh
Browse files Browse the repository at this point in the history
2023 refresh
  • Loading branch information
vallard authored Jan 4, 2023
2 parents 893fcba + b068f8d commit 7fd186c
Show file tree
Hide file tree
Showing 57 changed files with 6,058 additions and 26,792 deletions.
34 changes: 24 additions & 10 deletions 02/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Once it is created you can export the base64 version of that key with:
```
gpg --export [email protected] | base64 | pbcopy
```
This can be put inside the [terraform/iam/vars.tf](./terraform/iam/vars.tf) file.
This can be put inside the [terraform/iam/vars.tf](../terraform/iam/vars.tf) file.

## Create IAM resources with Terraform

Expand All @@ -81,7 +81,7 @@ We created the user with our `iam.tf` and we can use the output to log in as the
Get the User Password for Console Sign in

```
cd 02/iam
cd terraform/iam
export GPG_TTY=$(tty) # just to be sure.
terraform output -raw password | base64 --decode | gpg --decrypt | pbcopy
```
Expand Down Expand Up @@ -119,19 +119,22 @@ aws eks list-clusters



## Create Network with Terraform
## (Optional) More with Terraform

Do this as the `eksdude` user.
As the `eksdude` we can continue on in Terraform and start up the EKS cluster. However, at this point, we should instead move over to terragrunt as there are more capabilities we get from it. If you decide to do this portion, you may want to destroy it before moving on to Terragrunt at the end. (e.g: make the cluster but then destroy it when done.)


### Terraform the Network

```
cd 02/terraform/network
cd terraform/network
terraform init
terraform plan
terraform apply
```

## Create EKS with Terraform
### Create EKS with Terraform

```
cd 02/terraform/eks
Expand All @@ -140,19 +143,19 @@ terraform plan
terraform apply
```

## Log into EKS Cluster
### Log into EKS Cluster

We created the EKS cluster with a role rather than a user. Users may come and go in our system but we gave the user `eksdude` permissions to access the role that created the cluster.

### 1. Update `~/.kube/config`
#### 1. Update `~/.kube/config`

We add the cluster login permissions to the `config` file automatically by running:

```
aws eks update-kubeconfig --name eks-stage --alias eks-stage --role-arn arn:aws:iam::188966951897:role/eks_dude_role
```

### 2. Add the role
#### 2. Add the role

The above command adds the bottom role information to the kube config file. You will see lines similar to below:

Expand All @@ -163,7 +166,7 @@ The above command adds the bottom role information to the kube config file. You

To the `args:` list at the very end of the file. (Note: The account ID is my account ID and will need to be changed to match your account ID.)

### 3. Login
#### 3. Login

We can now log in:

Expand All @@ -173,6 +176,17 @@ kubectl get pods -n kube-system

This is a very basic use case of Terraform. Let's see how to do a few more advanced moves using Terragrunt in [our next section](./terragrunt.md)

### Delete the Cluster and Network

The previous network and EKS cluster should be deleted so we don't get charged for it! You can do this by doing the following:

```
cd terraform/eks
terraform destroy
cd terraform/network
terraform destroy
```



# Appendix: Deleting parts of the Terraform plan
Expand Down
21 changes: 0 additions & 21 deletions 02/terraform/eks/.terraform.lock.hcl

This file was deleted.

7 changes: 0 additions & 7 deletions 02/terraform/eks/backend.tf

This file was deleted.

57 changes: 0 additions & 57 deletions 02/terraform/eks/main.tf

This file was deleted.

21 changes: 0 additions & 21 deletions 02/terraform/iam/.terraform.lock.hcl

This file was deleted.

22 changes: 0 additions & 22 deletions 02/terraform/network/.terraform.lock.hcl

This file was deleted.

7 changes: 0 additions & 7 deletions 02/terraform/network/backend.tf

This file was deleted.

7 changes: 0 additions & 7 deletions 02/terraform/network/outputs.tf

This file was deleted.

4 changes: 0 additions & 4 deletions 02/terraform/network/provider.tf

This file was deleted.

33 changes: 0 additions & 33 deletions 02/terraform/network/vpc.tf

This file was deleted.

33 changes: 32 additions & 1 deletion 02/terragrunt.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,41 @@
# Terragrunt

For removing DRY issues!
[Terragrunt](https://terragrunt.gruntwork.io/) gives us the ability to reuse multiple modules and keep our environments [DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself). This is useful for the following reasons:

1. We can create reusable modules for production and stage environments.
2. We can string dependencies together. For example: EKS requires a network, so we can ensure the network is created first and then EKS.
3. One command to destroy and create all of the different modules.

In short, Terragrunt can be thought of as an even higher order infrastructure creation tool than Terraform. It is a wrapper around Terraform and it allows us to organize Terraform into "stacks" of things we want to create.


Let's create the entire infrastructure as follows:

```
cd terragrunt/stacks/stage
terragrunt run-all init
terragrunt run-all plan
terragrunt run-all destroy
```

That's it!

But what are we doing? In my class I explain these different components in the `stacks` directory and the `modules` directory. You can also read the Terragrunt documentation to see how it should be organized.

## Log into the EKS cluster

```
aws eks update-kubeconfig --name eks-stage --alias eks-stage --role-arn arn:aws:iam::188966951897:role/eks_dude_role
```

## Don't Type so much!

Edit `~/.profile` to contain:

```
alias k='kubectl'
```

Now instead of `kubectl` we can just type `k`.


32 changes: 0 additions & 32 deletions 02/terragrunt/modules/eks/main.tf

This file was deleted.

1 change: 1 addition & 0 deletions 03/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ An internal DNS service that allows pods to communicate. For example, suppose w
Let's create 2 pods and a service:

```
cd 03/
kubectl apply -f bb8.yaml
kubectl apply -f ngx.yaml
```
Expand Down
2 changes: 1 addition & 1 deletion 03/bb8.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
run: bb8
name: bb8
spec:
replicas: 2
replicas: 1
selector:
matchLabels:
run: bb8
Expand Down
Loading

0 comments on commit 7fd186c

Please sign in to comment.