Skip to content

Commit

Permalink
fix: Fix broken html for gitops getting started (#1822)
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Santana <[email protected]>
Co-authored-by: Bryant Biggs <[email protected]>
  • Loading branch information
csantanapr and bryantbiggs authored Nov 4, 2023
1 parent 2eae426 commit a20f0e2
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 27 deletions.
69 changes: 63 additions & 6 deletions patterns/gitops/getting-started-argocd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ This tutorial guides you through deploying an Amazon EKS cluster with addons con

<img src="https://raw.githubusercontent.com/aws-ia/terraform-aws-eks-blueprints/main/patterns/gitops/getting-started-argocd/static/gitops-bridge.drawio.png" width=100%>


The [GitOps Bridge Pattern](https://github.com/gitops-bridge-dev) enables Kubernetes administrators to utilize Infrastructure as Code (IaC) and GitOps tools for deploying Kubernetes Addons and Workloads. Addons often depend on Cloud resources that are external to the cluster. The configuration metadata for these external resources is required by the Addons' Helm charts. While IaC is used to create these cloud resources, it is not used to install the Helm charts. Instead, the IaC tool stores this metadata either within GitOps resources in the cluster or in a Git repository. The GitOps tool then extracts these metadata values and passes them to the Helm chart during the Addon installation process. This mechanism forms the bridge between IaC and GitOps, hence the term "GitOps Bridge."

Additional examples available on the [GitOps Bridge Pattern](https://github.com/gitops-bridge-dev):

- [argocd-ingress](https://github.com/gitops-bridge-dev/gitops-bridge/tree/main/argocd/iac/terraform/examples/eks/argocd-ingress)
- [aws-secrets-manager](https://github.com/gitops-bridge-dev/gitops-bridge/tree/main/argocd/iac/terraform/examples/eks/aws-secrets-manager)
- [crossplane](https://github.com/gitops-bridge-dev/gitops-bridge/tree/main/argocd/iac/terraform/examples/eks/crossplane)
Expand All @@ -17,49 +17,58 @@ Additional examples available on the [GitOps Bridge Pattern](https://github.com/
- [multi-cluster/hub-spoke-shared](https://github.com/gitops-bridge-dev/gitops-bridge/tree/main/argocd/iac/terraform/examples/eks/multi-cluster/hub-spoke-shared)
- [private-git](https://github.com/gitops-bridge-dev/gitops-bridge/tree/main/argocd/iac/terraform/examples/eks/private-git)



## Prerequisites

Before you begin, make sure you have the following command line tools installed:

- git
- terraform
- kubectl
- argocd

## (Optional) Fork the GitOps git repositories
See the appendix section [Fork GitOps Repositories](#fork-gitops-repositories) for more info on the terraform variables to override.

See the appendix section [Fork GitOps Repositories](#fork-gitops-repositories) for more info on the terraform variables to override.

## Deploy the EKS Cluster

Initialize Terraform and deploy the EKS cluster:

```shell
terraform init
terraform apply -target="module.vpc" -auto-approve
terraform apply -target="module.eks" -auto-approve
terraform apply -auto-approve
```

To retrieve `kubectl` config, execute the terraform output command:

```shell
terraform output -raw configure_kubectl
```

The expected output will have two lines you run in your terminal

```text
export KUBECONFIG="/tmp/getting-started-gitops"
aws eks --region us-west-2 update-kubeconfig --name getting-started-gitops
```

>The first line sets the `KUBECONFIG` environment variable to a temporary file
that includes the cluster name. The second line uses the `aws` CLI to populate
that temporary file with the `kubectl` configuration. This approach offers the
advantage of not altering your existing `kubectl` context, allowing you to work
in other terminal windows without interference.


Terraform will add GitOps Bridge Metadata to the ArgoCD secret.
The annotations contain metadata for the addons' Helm charts and ArgoCD ApplicationSets.

```shell
kubectl get secret -n argocd -l argocd.argoproj.io/secret-type=cluster -o json | jq '.items[0].metadata.annotations'
```

The output looks like the following:

```json
{
"addons_repo_basepath": "argocd/",
Expand All @@ -81,11 +90,15 @@ The output looks like the following:
"workload_repo_url": "https://github.com/csantanapr/terraform-aws-eks-blueprints"
}
```

The labels offer a straightforward way to enable or disable an addon in ArgoCD for the cluster.

```shell
kubectl get secret -n argocd -l argocd.argoproj.io/secret-type=cluster -o json | jq '.items[0].metadata.labels' | grep -v false | jq .
```

The output looks like the following:

```json
{
"argocd.argoproj.io/secret-type": "cluster",
Expand All @@ -100,19 +113,25 @@ The output looks like the following:
```

## Deploy the Addons

Bootstrap the addons using ArgoCD:

```shell
kubectl apply -f bootstrap/addons.yaml
```

### Monitor GitOps Progress for Addons

Wait until all the ArgoCD applications' `HEALTH STATUS` is `Healthy`.
Use `Ctrl+C` or `Cmd+C` to exit the `watch` command. ArgoCD Applications
can take a couple of minutes in order to achieve the Healthy status.

```shell
kubectl get applications -n argocd -w
```

The expected output should look like the following:

```text
NAME SYNC STATUS HEALTH STATUS
addon-in-cluster-argo-cd Synced Healthy
Expand All @@ -122,7 +141,9 @@ cluster-addons Synced Healthy
```

### Verify the Addons

Verify that the addons are ready:

```shell
kubectl get deployment -n kube-system \
aws-load-balancer-controller \
Expand All @@ -132,7 +153,9 @@ kubectl get deploy -n argocd \
argo-cd-argocd-repo-server \
argo-cd-argocd-server
```

The expected output should look like the following:

```text
NAME READY UP-TO-DATE AVAILABLE AGE
aws-load-balancer-controller 2/2 2 2 7m21s
Expand All @@ -142,46 +165,59 @@ argo-cd-argocd-repo-server 1/1 1 1 109m
argo-cd-argocd-server 1/1 1 1 109m
```


## (Optional) Access ArgoCD

Access to the ArgoCD's UI is completely optional, if you want to do it,
run the commands shown in the Terraform output as the example below:

```shell
terraform output -raw access_argocd
```

The expected output should contain the `kubectl` config followed by `kubectl` command to retrieve
the URL, username, password to login into ArgoCD UI or CLI.

```text
echo "ArgoCD Username: admin"
echo "ArgoCD Password: $(kubectl get secrets argocd-initial-admin-secret -n argocd --template="{{index .data.password | base64decode}}")"
echo "ArgoCD URL: https://$(kubectl get svc -n argocd argo-cd-argocd-server -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')"
```

## Deploy the Workloads

Deploy a sample application located in [k8s/game-2048.yaml](k8s/game-2048.yaml) using ArgoCD:

```shell
kubectl apply -f bootstrap/workloads.yaml
```

### Monitor GitOps Progress for Workloads

Wait until all the ArgoCD applications' `HEALTH STATUS` is `Healthy`.
Use `Ctrl+C` or `Cmd+C` to exit the `watch` command. ArgoCD Applications
can take a couple of minutes in order to achieve the Healthy status.

```shell
watch kubectl get -n argocd applications workloads
```

The expected output should look like the following:

```text
NAME SYNC STATUS HEALTH STATUS
workloads Synced Healthy
```

### Verify the Application

Verify that the application configuration is present and the pod is running:

```shell
kubectl get -n game-2048 deployments,service,ep,ingress
```

The expected output should look like the following:

```text
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/game-2048 1/1 1 1 7h59m
Expand All @@ -200,50 +236,67 @@ AWS Load Balancer can take a couple of minutes in order to be created.

Run the following command and wait until and event for ingress `game-2048` contains `Successfully reconciled`.
Use `Ctrl+C` or `Cmd+C`to exit the `watch` command.

```shell
kubectl events -n game-2048 --for ingress/game-2048 --watch
```

The expected output should look like the following:

```text
LAST SEEN TYPE REASON OBJECT MESSAGE
11m Normal SuccessfullyReconciled Ingress/game-2048 Successfully reconciled
```

### Access the Application using AWS Load Balancer

Verify the application endpoint health using `wget`:

```shell
kubectl exec -n game-2048 deploy/game-2048 -- \
wget -S --spider $(kubectl get -n game-2048 ingress game-2048 -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')
```

The expected output should look like the following:

```text
HTTP/1.1 200 OK
Date: Wed, 01 Nov 2023 22:44:57 GMT
Content-Type: text/html
Content-Length: 3988
```

>A success response should contain `HTTP/1.1 200 OK`.
Retrieve the ingress URL to access the application in your local web browser.

```shell
echo "Application URL: http://$(kubectl get -n game-2048 ingress game-2048 -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')"
```

### Container Metrics

Check the application's CPU and memory metrics:

```shell
kubectl top pods -n game-2048
```

The expected output should look like the following:

```text
NAME CPU(cores) MEMORY(bytes)
game-2048-66fb78b995-hqbjv 1m 2Mi
```

Check the CPU and memory metrics for all pods for Addons and Workloads:

```shell
kubectl top pods -A
```

The expected output should look like the following:

```text
NAMESPACE NAME CPU(cores) MEMORY(bytes)
argocd argo-cd-argocd-application-controller-0 43m 138Mi
Expand All @@ -266,17 +319,21 @@ kube-system metrics-server-5b76987ff-5gzsv 4m
```

## Destroy the EKS Cluster

To tear down all the resources and the EKS cluster, run the following command:

```shell
./destroy.sh
```

## Appendix

## Fork GitOps Repositories

To modify the `values.yaml` file for addons or the workload manifest files (.ie yaml), you'll need to fork two repositories: [aws-samples/eks-blueprints-add-ons](https://github.com/aws-samples/eks-blueprints-add-ons) for addons and [github.com/aws-ia/terraform-aws-eks-blueprints](https://github.com/aws-ia/terraform-aws-eks-blueprints) for workloads located in this pattern directory.

After forking, update the following environment variables to point to your forks, replacing the default values.

```shell
export TF_VAR_gitops_addons_org=https://github.com/aws-samples
export TF_VAR_gitops_addons_repo=eks-blueprints-add-ons
Expand Down
2 changes: 1 addition & 1 deletion patterns/gitops/getting-started-argocd/k8s/game-2048.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ spec:
service:
name: game-2048
port:
name: http
name: http

Large diffs are not rendered by default.

Loading

0 comments on commit a20f0e2

Please sign in to comment.