-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from vallard/2023-refresh
2023 refresh
- Loading branch information
Showing
57 changed files
with
6,058 additions
and
26,792 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
|
@@ -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 | ||
``` | ||
|
@@ -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 | ||
|
@@ -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: | ||
|
||
|
@@ -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: | ||
|
||
|
@@ -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 | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -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`. | ||
|
||
|
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
|
@@ -5,7 +5,7 @@ metadata: | |
run: bb8 | ||
name: bb8 | ||
spec: | ||
replicas: 2 | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
run: bb8 | ||
|
Oops, something went wrong.