Skip to content

Instantly share code, notes, and snippets.

@faermanj
Last active April 9, 2025 09:22
Show Gist options
  • Save faermanj/b70543cbde0122a07a7c25c68ea9008b to your computer and use it in GitHub Desktop.
Save faermanj/b70543cbde0122a07a7c25c68ea9008b to your computer and use it in GitHub Desktop.
CAPA Quickstart
# Local settings
LOCAL_OS=$(uname -s | tr '[:upper:]' '[:lower:]')
LOCAL_ARCH=$(uname -m)
# Map architecture from uname to Cluster API release architecture names
if [ "$LOCAL_ARCH" == "x86_64" ]; then
LOCAL_ARCH="amd64"
elif [ "$LOCAL_ARCH" == "aarch64" ]; then
LOCAL_ARCH="arm64"
fi
export LOCAL_OS
export LOCAL_ARCH
echo $LOCAL_OS $LOCAL_ARCH
# Create management cluster
KUBERNETES_VERSION=v1.30.8
CLUSTER_NAME=capi-test
kind create cluster --name=$CLUSTER_NAME --image kindest/node:$KUBERNETES_VERSION
# Download Cluster API
CLUSTERCTL_VERSION=v1.9.5
curl -L https://github.com/kubernetes-sigs/cluster-api/releases/download/$CLUSTERCTL_VERSION/clusterctl-linux-amd64 -o clusterctl
chmod +x clusterctl
mv clusterctl $HOME/.local/bin/
clusterctl version
# Download CAPI AWS Provider
CLUSTERAWSADM_VERSION=v2.7.1
curl -L https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases/download/$CLUSTERAWSADM_VERSION/clusterawsadm-linux-amd64 -o clusterawsadm
chmod +x clusterawsadm
mv clusterawsadm $HOME/.local/bin/
clusterawsadm version
# Verify AWS authentication
aws sts get-caller-identity
export AWS_REGION=us-east-1
# Create IAM resources and fetch encoded credentials
clusterawsadm bootstrap iam create-cloudformation-stack
export AWS_B64ENCODED_CREDENTIALS=$(clusterawsadm bootstrap credentials encode-as-profile)
# Initialize AWS provider
clusterctl init --infrastructure aws
# Initialize AWS configuration
export AWS_SSH_KEY_NAME="capa-quickstart"
export AWS_CONTROL_PLANE_MACHINE_TYPE="t3.large"
export AWS_NODE_MACHINE_TYPE="t3.large"
# Check if the AWS SSH key exists
aws ec2 describe-key-pairs --query "KeyPairs[?KeyName=='$AWS_SSH_KEY_NAME']"
# Set cluster name
export CLUSTER_NAME=capa-quickstart
# Generate cluster manifest
KUBERNETES_OS="ubuntu-24.04"
clusterctl generate cluster "$CLUSTER_NAME" \
--kubernetes-version $KUBERNETES_VERSION \
--os $KUBERNETES_OS \
--control-plane-machine-count=3 \
--worker-machine-count=3 \
> "${CLUSTER_NAME}.yaml"
# Add to yaml / troubleshooting
# fixed by https://github.com/kubernetes-sigs/cluster-api-provider-aws/pull/5345
controlPlaneLoadBalancer:
loadBalancerType: nlb
# Create workload cluster
kubectl apply -f "${CLUSTER_NAME}.yaml"
# Wait until cluster control plane is initialized
watch -n 15 kubectl get kubeadmcontrolplane
watch -n 15 clusterctl describe cluster "$CLUSTER_NAME"
# Fetch kubeconfig
clusterctl get kubeconfig "$CLUSTER_NAME" > "${CLUSTER_NAME}.kubeconfig"
# Install CNI
CALICO_VERSION=v3.26.1
kubectl --kubeconfig="./${CLUSTER_NAME}.kubeconfig" \
apply -f https://raw.githubusercontent.com/projectcalico/calico/$CALICO_VERSION/manifests/calico.yaml
# Check that all nodes are ready
kubectl --kubeconfig="./${CLUSTER_NAME}.kubeconfig" get nodes
# ...
# Dispose
kubectl delete cluster "$CLUSTER_NAME"
kind delete cluster
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment