Skip to content

Commit

Permalink
KubeCon
Browse files Browse the repository at this point in the history
  • Loading branch information
vfarcic committed Oct 31, 2023
1 parent c6b69da commit 5cef7ed
Show file tree
Hide file tree
Showing 23 changed files with 387 additions and 289 deletions.
2 changes: 1 addition & 1 deletion argocd/helm-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ configs:
argocdServerAdminPasswordMtime: "2021-11-08T15:04:05Z"
cm:
application.resourceTrackingMethod: annotation
# timeout.reconciliation: 60s
timeout.reconciliation: 60s
server:
extraArgs:
- --insecure
2 changes: 2 additions & 0 deletions manuscript/app/carvel.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ TODO: Intro
* Watch https://youtu.be/U8zCHA-9VLA if you are not familiar with Charm Gum.

```bash
chmod +x manuscript/app/carvel.sh

./manuscript/app/carvel.sh

source .env
Expand Down
7 changes: 5 additions & 2 deletions manuscript/app/carvel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ if [ -z "$INGRESS_CLASS_NAME" ]; then
fi

if [[ "$GITOPS_APP" == "argocd" ]]; then
REPO_URL=$(git config --get remote.origin.url)
yq --inplace ".spec.source.repoURL = \"$REPO_URL\"" $GITOPS_APP/cncf-demo-ytt.yaml
fi

if [[ "$GITOPS_APP" == "kapp-controller" ]]; then
REPO_URL=$(git config --get remote.origin.url)
yq --inplace ".spec.fetch[0].git.url = \"$REPO_URL\"" $GITOPS_APP/cncf-demo-ytt.yaml
fi
Expand All @@ -52,8 +57,6 @@ if [ -z "$TAG" ]; then
echo "export TAG=$TAG" >> .env
fi

yq --inplace ".spec.fetch[0].git.url = \"$REPO_URL\"" $GITOPS_APP/cncf-demo-ytt.yaml

if [ -z "$INGRESS_IP" ]; then
INGRESS_IP=$(yq ".production.ingress.ip" settings.yaml)
fi
Expand Down
27 changes: 6 additions & 21 deletions manuscript/app/cdk8s.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,15 @@ TODO: Intro

## Setup

```bash
export GITOPS_APP=$(yq ".gitOps.app" settings.yaml)

export DOMAIN=$(yq ".production.domain" settings.yaml)

export INGRESS_CLASS_NAME=$(\
yq ".production.ingress.className" settings.yaml)

# Execute the command that follows only if you are using Argo CD
export REPO_URL=$(git config --get remote.origin.url)
* Install `gum` by following the instructions in https://github.com/charmbracelet/gum#installation.
* Watch https://youtu.be/U8zCHA-9VLA if you are not familiar with Charm Gum.

# Execute the command that follows only if you are using Argo CD
yq --inplace ".spec.source.repoURL = \"$REPO_URL\"" \
$GITOPS_APP/cncf-demo-cdk8s.yaml

export TAG=$(yq ".tag" settings.yaml)

export INGRESS_IP=$(yq ".production.ingress.ip" settings.yaml)
```bash
chmod +x manuscript/app/cdk8s.sh

echo $INGRESS_IP
./manuscript/app/cdk8s.sh

# Configure DNS for the following subdomains (skip this step if
# you chose to use `nip.io` instead of a "real" domain):
# - cncf-demo
source .env
```

## Do
Expand Down
68 changes: 68 additions & 0 deletions manuscript/app/cdk8s.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/sh
set -e

gum style \
--foreground 212 --border-foreground 212 --border double \
--margin "1 2" --padding "2 4" \
'Setup for the Deploy The App Defined As cdk8s To Production With GitOps chapter.'

gum confirm '
Are you ready to start?
Select "Yes" only if you did NOT follow the story from the start (if you jumped straight into this chapter).
Feel free to say "No" and inspect the script if you prefer setting up resources manually.
' || exit 0

echo "
## You will need following tools installed:
|Name |Required |More info |
|----------------|---------------------|---------------------------------------------------|
|yq |Yes |'https://github.com/mikefarah/yq#install' |
" | gum format

gum confirm "
Do you have those tools installed?
" || exit 0

#########
# Setup #
#########

if [ -z "$GITOPS_APP" ]; then
GITOPS_APP=$(yq ".gitOps.app" settings.yaml)
echo "export GITOPS_APP=$GITOPS_APP" >> .env
fi

if [ -z "$DOMAIN" ]; then
DOMAIN=$(yq ".production.domain" settings.yaml)
echo "export DOMAIN=$DOMAIN" >> .env
fi

if [ -z "$INGRESS_CLASS_NAME" ]; then
INGRESS_CLASS_NAME=$(yq ".production.ingress.className" settings.yaml)
echo "export INGRESS_CLASS_NAME=$INGRESS_CLASS_NAME" >> .env
fi

if [[ "$GITOPS_APP" == "argocd" ]]; then
REPO_URL=$(git config --get remote.origin.url)
yq --inplace ".spec.source.repoURL = \"$REPO_URL\"" $GITOPS_APP/cncf-demo-cdk8s.yaml
fi

if [ -z "$TAG" ]; then
TAG=$(yq ".tag" settings.yaml)
echo "export TAG=$TAG" >> .env
fi

if [ -z "$INGRESS_IP" ]; then
INGRESS_IP=$(yq ".production.ingress.ip" settings.yaml)
fi

gum style \
--foreground 212 --border-foreground 212 --border double \
--margin "1 2" --padding "2 4" \
"Use the IP $INGRESS_IP to configure DNS for the following subdomains." \
'(Skip this step if you chose to use `nip.io` instead of a "real" domain.)
- cncf-demo'

gum confirm "
Continue?
" || exit 0
28 changes: 3 additions & 25 deletions manuscript/app/kubecon-cdk8s.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,9 @@ TODO: Intro
## Setup

```bash
export GITOPS_APP=$(yq ".gitOps.app" settings.yaml)
./manuscript/app/cdk8s.sh

export DOMAIN=$(yq ".production.domain" settings.yaml)

export INGRESS_CLASS_NAME=$(\
yq ".production.ingress.className" settings.yaml)

# Execute the command that follows only if you are using Argo CD
export REPO_URL=$(git config --get remote.origin.url)

# Execute the command that follows only if you are using Argo CD
yq --inplace ".spec.source.repoURL = \"$REPO_URL\"" \
$GITOPS_APP/cncf-demo-cdk8s.yaml

export TAG=$(yq ".tag" settings.yaml)

export INGRESS_IP=$(yq ".production.ingress.ip" settings.yaml)

echo $INGRESS_IP

# Configure DNS for the following subdomains (skip this step if
# you chose to use `nip.io` instead of a "real" domain):
# - cncf-demo
source .env
```

## Do
Expand Down Expand Up @@ -63,9 +43,7 @@ git push

kubectl --namespace production get all,ingresses

# If you chose to use `nip.io` instead of a "real" domain,
# replace `https` with `http`.
echo "https://cncf-demo.$DOMAIN"
echo "http://cncf-demo.$DOMAIN"

# Open it in a browser.
```
Expand Down
42 changes: 24 additions & 18 deletions manuscript/cluster/capi-aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Among other things, this involves:
Once this is done, we are able to provision Kubernetes clusters in AWS using Cluster API.

## Setup

To begin you must install the following:
1. [clusterawsadm CLI](https://cluster-api-aws.sigs.k8s.io/topics/using-clusterawsadm-to-fulfill-prerequisites.html#using-clusterawsadm-to-fulfill-prerequisites)

Expand All @@ -34,44 +35,47 @@ aws ec2 create-key-pair --key-name default --output json | jq .KeyMaterial -r
## NOTE: Only RSA keys are supported by AWS.
aws ec2 import-key-pair --key-name default --public-key-material "$(cat ~/.ssh/id_rsa.pub)"


# Export Environment Variables
export CLUSTER_TOPOLOGY=true

export EXP_CLUSTER_RESOURCE_SET=true

export EXP_MACHINE_POOL=true

export CAPA_EKS_IAM=true

export CAPA_EKS_ADD_ROLES=true

export EXP_EKS_FARGATE=true

export AWS_B64ENCODED_CREDENTIALS=$(clusterawsadm bootstrap credentials encode-as-profile)

# Install ClusterAPI Provider for AWS
clusterctl init --infrastructure aws

# Set the SSH Key pair name as created above
export AWS_SSH_KEY_NAME=default

# Select worker node instance types
export AWS_NODE_MACHINE_TYPE=t3.large

yq --inplace ".capi.destination = \"aws\"" settings.yaml
```

## Do

```bash
# Set values
# Replace `[...]` with your desired region
export AWS_REGION=`[...]`

# Set the SSH Key pair name as created above
export AWS_SSH_KEY_NAME=default
# Select worker node instance types
export AWS_NODE_MACHINE_TYPE=t3.large

# Generate cluster manifest
clusterctl generate cluster production --flavor eks-managedmachinepool-vpccni --kubernetes-version v1.24.1 --worker-machine-count=3 > capi/aws-eks.yaml
clusterctl generate cluster production \
--flavor eks-managedmachinepool-vpccni \
--kubernetes-version v1.28.1 --worker-machine-count 3 \
--target-namespace production \
| tee capi/aws-eks.yaml

# Create the cluster
kubectl --namespace production apply --filename capi/aws-eks.yaml
kubectl apply --filename capi/aws-eks.yaml

kubectl --namespace production get Cluster
kubectl --namespace production get AWSManagedCluster
kubectl --namespace production get AWSManagedControlPlane
kubectl --namespace production get MachinePool
kubectl --namespace production get AWSManagedMachinePool
kubectl --namespace production get \
clusters,awsmanagedclusters,awsmanagedcontrolplanes,machinepools,awsmanagedmachinepools

cat capi/get-kubeconfig-aws.sh

Expand All @@ -86,6 +90,8 @@ yq --inplace \
settings.yaml

kubectl get nodes

kubectl create namespace production
```

## Continue the adventure
Expand Down
2 changes: 2 additions & 0 deletions manuscript/cluster/capi-azure.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ yq --inplace \
settings.yaml

kubectl get nodes

kubectl create namespace production
```

## Continue the adventure
Expand Down
2 changes: 2 additions & 0 deletions manuscript/cluster/capi-google.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ yq --inplace \
settings.yaml

kubectl get nodes

kubectl create namespace production
```

## Continue the Adventure
Expand Down
30 changes: 30 additions & 0 deletions manuscript/cluster/kubecon-capi-aws.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Create and Manage Production AWS EKS Cluster with ClusterAPI

## Do

```bash
clusterctl generate cluster production \
--flavor eks-managedmachinepool-vpccni \
--kubernetes-version v1.28.1 --worker-machine-count 3 \
--target-namespace production \
| tee capi/aws-eks.yaml

kubectl apply --filename capi/aws-eks.yaml

kubectl --namespace production get \
clusters,awsmanagedclusters,awsmanagedcontrolplanes,machinepools,awsmanagedmachinepools

./capi/get-kubeconfig-aws.sh

export KUBECONFIG=$PWD/kubeconfig-prod.yaml

kubectl get nodes

kubectl create namespace production
```

## Continue the adventure

* [Flux](../gitops/kubecon-flux.md)
* [Argo CD](../gitops/kubecon-argocd.md)
* [Carvel kapp-controller](../gitops/kubecon-kapp.md)
1 change: 0 additions & 1 deletion manuscript/cluster/kubecon-cluster-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ First you need to install:
1. [Docker](https://www.docker.com/)
2. [Kubectl](https://kubernetes.io/docs/tasks/tools/)
2. [Clusterctl](https://cluster-api.sigs.k8s.io/user/quick-start.html#install-clusterctl)
3. [Kind](https://kind.sigs.k8s.io/docs/user/quick-start#installation)

```bash
# Export environment variables
Expand Down
17 changes: 13 additions & 4 deletions manuscript/destroy/production.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,33 @@ elif [[ "$HYPERSCALER" == "aws" ]]; then

git push

COUNTER=$(kubectl get managed | grep -v object | grep -v release | grep -v database | wc -l)
set +e
COUNTER=$(kubectl get managed --no-headers | grep -v object | grep -v release | grep -v database | wc -l)

while [ $COUNTER -ne 0 ]; do
sleep 10
COUNTER=$(kubectl get managed | grep -v object | grep -v release | grep -v database | wc -l)
COUNTER=$(kubectl get managed --no-headers | grep -v object | grep -v release | grep -v database | wc -l)
done
set -e

unset KUBECONFIG

set +e
kubectl --namespace production delete --filename crossplane/aws-eks.yaml

COUNTER=$(kubectl get managed | grep -v object | grep -v release | wc -l)
COUNTER=$(kubectl get managed --no-headers | grep -v object | grep -v release | wc -l)

while [ $COUNTER -ne 0 ]; do
sleep 10
COUNTER=$(kubectl get managed | grep -v object | grep -v release | wc -l)
COUNTER=$(kubectl get managed --no-headers | grep -v object | grep -v release | wc -l)
done

kubectl delete --filename capi/aws-eks.yaml

clusterawsadm bootstrap iam delete-cloudformation-stack --config capi-config/capa-iam-config.yaml

set -e

elif [[ "$HYPERSCALER" == "azure" ]]; then

az group delete --name $RESOURCE_GROUP --yes
Expand Down
9 changes: 5 additions & 4 deletions manuscript/gitops/argocd.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ We also create an Argo CD Application that will eventually watch our Hero applic

## Setup

* Install `gum` by following the instructions in https://github.com/charmbracelet/gum#installation.
* Watch https://youtu.be/U8zCHA-9VLA if you are not familiar with Charm Gum.

```bash
# Set the environment variable REPO_URL to point to the 'argocd/apps.yaml' file in your remote Git repository
chmod +x manuscript/gitops/argocd.sh

export REPO_URL=$(git config --get remote.origin.url)
./manuscript/gitops/argocd.sh

yq --inplace ".spec.source.repoURL = \"$REPO_URL\"" \
argocd/apps.yaml
source .env
```

## Do
Expand Down
Loading

0 comments on commit 5cef7ed

Please sign in to comment.