Skip to content

Commit bcc200b

Browse files
committed
feat: Add ArgoCD to the bootstraped cluster
1 parent 376964e commit bcc200b

File tree

6 files changed

+170
-37
lines changed

6 files changed

+170
-37
lines changed

.terraform.lock.hcl

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
# Oracle OKE Terraform
22

3-
This repository contains the required Terraform scripts to set up K8s using OKE in the Oracle Free Tier.
3+
This repository contains the **Terraform** scripts to bootstrap a Kubernetes Cluster in the **Oracle Cloud Infrastructure Free Tier** with **Oracle Kubernetes Engine (OKE)**.
4+
5+
Additionally, **ArgoCD** will be installed in the bootstrapped cluster for GitOps management of the cluster resources.
46

57
## Requirements
68

9+
### Variables
10+
11+
This variables don't have default declared values and are required to be provided to the scripts.
12+
13+
Create a `.tfvars` file in the root folder of this repository with the following variables declared:
14+
715
| Variable | Definition |
816
| -------- | ---------------- |
917
| `region` | Value of the region where we want to deploy the cluster |
@@ -12,21 +20,13 @@ This repository contains the required Terraform scripts to set up K8s using OKE
1220
| `user_rsa_path` | Path where we store the generated RSA key, better to use `~/.oci/oci-rsa.pem` |
1321
| `user_rsa_fingerprint` | After generating the RSA Keys, we can consult the fingerprint in the Oracle Cloud Console |
1422

15-
### OCI CLI
16-
17-
We will require from the OCI CLI to access to our created Kubernetes Cluster, so this should be installed.
23+
Other variables, which are not mandatory, can be provided in this file as well. For a complete description of all the variables, check the contents on the [variables.tf file](variables.tf).
1824

19-
Instructions on how to install the OCI CLI for different environments can be found [here](https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/cliinstall.htm).
20-
21-
### Kubectl
22-
23-
In order to interact with our K8s Cluster using the Kubernetes API, we require the command-line tool for Kubernetes: `kubectl`.
25+
### Oracle Cloud Infrastructure (OCI) Access
2426

25-
How to install it in different environments is available in [here](https://kubernetes.io/docs/tasks/tools/#kubectl)
27+
In order to be able to perform operations against OCI, we need to create and import an RSA Key for API signing.
2628

27-
### RSA Keys
28-
29-
In order to be able to run this scripts against OCI (Oracle Cloud Infrastructure), you have to create and import RSA Keys for API signing.
29+
This can be easily performed with the following steps:
3030

3131
1. Make an `.oci` directory on your home folder:
3232

@@ -55,7 +55,13 @@ $ cat $HOME/.oci/oci-rsa-public.pem
5555

5656
5. Add the public key to your OCI user account from `User Settings > API Keys`
5757

58-
6. Modify the file under `$HOME/.oci/config` and add the following keys:
58+
### Oracle Cloud Infrastructure (OCI) CLI
59+
60+
We need a correctly configured OCI CLI to log against our to-be-created Kubernetes Cluster, as we will use the K8s login plugin to get a JWT for access.
61+
62+
Instructions on how to install the OCI CLI for different environments can be found [here](https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/cliinstall.htm).
63+
64+
Once we have installed the tool, we need to configure it to use the previously generated RSA Key to interact with out OCI Tenancy. In order to do that, we are going to create (or modify if it has been automatically created) the file `$HOME/.oci/config` with the following keys:
5965

6066
```text
6167
tenancy=<tenancy_ocid>
@@ -65,28 +71,39 @@ key_file=<user_rsa_path>
6571
fingerprint=<user_rsa_fingerprint>
6672
```
6773

74+
How to retrieve these values is explained in the [variables section](#variables).
75+
76+
### Kubernetes Command-Line Tool
77+
78+
In order to interact with our K8s Cluster using the Kubernetes API, we require a Kubernetes CLI; at this point, it's on your choice whether to use install the official CLI from Kubernetes (`kubectl`) or some other CLI tool as K9s (as I personally use).
79+
80+
- How to install `kubectl` in different environments is available in [here](https://kubernetes.io/docs/tasks/tools/#kubectl)
81+
- How to install `k9s` in different environments is available in [here](https://k9scli.io/topics/install/)
82+
6883
## Usage
6984

7085
First, override all the variables by using a file in the root directory of our Terraform scripts with the defined variables in the [Requirement](#requirements) section with the name `env.tfvars`.
7186

7287
Then, in order to create the cluster, just run the following:
7388

7489
```shell
75-
terraform apply -var-file="env.tfvars"
90+
$ terraform apply -var-file="env.tfvars"
7691
```
7792

7893
Check that everything is correct, and type `yes` on the required input. In some minutes, the cluster will be ready and a `kubeconfig` will be placed in the folder `generated`.
7994

80-
In order to start using this cluster, you can just:
81-
82-
- Move the kubeconfig to the default location of `$HOME/.kube/config`
95+
In order to start using this cluster, you can just export the `KUBECONFIG` environment variable to our current location and use your desired Kubernetes CLI Tool.
8396

8497
```shell
85-
mv /generated/kubeconfig ~/.kube/config
98+
$ export KUBECONFIG=$(pwd)/generated/kubeconfig
99+
$ k9s
86100
```
87101

88-
- Export the `KUBECONFIG` environment variable to our current location
102+
## Author
89103

90-
```shell
91-
export KUBECONFIG=$(pwd)/generated/kubeconfig
92-
```
104+
Daniel Campos Olivares, 2022
105+
106+
**Links:**
107+
- [StackOverflow](https://stackoverflow.com/users/8951571/daniel-campos-olivares)
108+
- [Twitter](https://www.twitter.com/devcamposol/)
109+
- [LinkedIn](https://www.linkedin.com/in/dacamposol/)

access.tf

Lines changed: 0 additions & 7 deletions
This file was deleted.

argo.tf

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# === ArgoCD ===
2+
3+
## Namespace
4+
5+
resource "kubernetes_namespace" "argo" {
6+
metadata {
7+
name = var.argo_cd_namespace
8+
}
9+
10+
depends_on = [
11+
module.oke
12+
]
13+
}
14+
15+
## Resources
16+
17+
data "http" "install" {
18+
url = "https://raw.githubusercontent.com/argoproj/argo-cd/v${var.argo_cd_version}/manifests/install.yaml"
19+
}
20+
21+
locals {
22+
manifests = split("\n---\n", data.http.install.response_body)
23+
}
24+
25+
resource "k8s_manifest" "argo" {
26+
count = length(local.manifests)
27+
28+
content = local.manifests[count.index]
29+
namespace = var.argo_cd_namespace
30+
depends_on = [
31+
kubernetes_namespace.argo
32+
]
33+
}

main.tf

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,45 @@
11
terraform {
22
required_providers {
33
oci = {
4-
source = "oracle/oci"
4+
source = "oracle/oci"
55
version = "4.96.0"
66
}
7+
8+
kubernetes = {
9+
source = "hashicorp/kubernetes"
10+
version = ">= 1.13.0"
11+
}
12+
13+
k8s = {
14+
source = "banzaicloud/k8s"
15+
version = ">= 0.8.0"
16+
}
717
}
818
}
919

1020
# == Provider ==
1121

1222
provider "oci" {
13-
region = var.region
23+
region = var.region
1424
tenancy_ocid = var.tenancy_ocid
15-
16-
user_ocid = var.user_ocid
25+
26+
user_ocid = var.user_ocid
1727
private_key_path = var.user_rsa_path
18-
fingerprint = var.user_rsa_fingerprint
28+
fingerprint = var.user_rsa_fingerprint
29+
}
30+
31+
provider "kubernetes" {
32+
config_path = "${path.module}/generated/kubeconfig"
33+
}
34+
35+
provider "k8s" {
36+
config_path = "${path.module}/generated/kubeconfig"
1937
}
2038

2139
# == Compartment ==
2240

2341
resource "oci_identity_compartment" "k8s" {
2442
compartment_id = var.tenancy_ocid
25-
description = "Compartment for Free Tier K8s Cluster"
26-
name = "OracleManagedKubernetesCompartment"
43+
description = "Compartment for Free Tier K8s Cluster"
44+
name = "OracleManagedKubernetesCompartment"
2745
}

variables.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,16 @@ variable user_rsa_fingerprint {
2727
type = string
2828
sensitive = true
2929
}
30+
31+
variable argo_cd_version {
32+
description = "Value of the ArgoCD version to be deployed"
33+
type = string
34+
default = "2.5.0"
35+
}
36+
37+
variable argo_cd_namespace {
38+
description = "Value of the Kubernetes namespace where to deploy ArgoCD resources"
39+
type = string
40+
default = "argo"
41+
}
42+

0 commit comments

Comments
 (0)