Skip to content

Instantly share code, notes, and snippets.

@detiber
Created February 22, 2019 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save detiber/8f61767b6d39d65aceab89d5a92589c4 to your computer and use it in GitHub Desktop.
Save detiber/8f61767b6d39d65aceab89d5a92589c4 to your computer and use it in GitHub Desktop.
Using CAPA from a management cluster

Using CAPA from an existing Kubernetes cluster

Prerequisites

Build clusterctl and clusterawsadm from the master branch of (cluster-api-provider-aws)[https://github.com/kubernetes-sigs/cluster-api-provider-aws]

make clusterctl clusterawsadm

Set AWS environment variables:

export AWS_REGION=us-east-1
export AWS_ACCESS_KEY_ID=<your aws access key id>
export AWS_SECRET_ACCESS_KEY=<your aws secret access key>

Deploy the CloudFormation Stack for the AWS pre-requisites:

clusterawsadm alpha bootstrap create-stack

Create the example manifests:

pushd cmd/clusterctl/examples/aws
./generate_yaml.sh
popd

This will create a subdirectory named out with four files:

  • addons.yaml (default addons to apply to created clusters, currently only deploys the Calico CNI provider components)
  • cluster.yaml (A Cluster definition for a Cluster named test1)
  • machines.yaml (A MachineList definition containing one control plane node and one worker node)
  • provider-components.yaml (Definitions for the necessary components for running cluster-api and cluster-api-provider-aws, this also includes a Secret generated from the AWS environment variables that were set earlier)

Deploying the cluster-api and cluster-api-provider-aws components to the management cluster

kubectl create -f cmd/clusterctl/examples/aws/out/provider-components.yaml

Deploying the Cluster object

kubectl create -f cmd/clusterctl/examples/aws/out/cluster.yaml

Deploy the Machine object for the control plane node

Currently clusterctl does not provide a way to extract just the control plane machine from the MachineList in machines.yaml when running individual phases, so this step will need to be done manually. This assumes that a new file controlplane.yaml was created with just the control plane node object defined in machines.yaml

kubectl create -f cmd/clusterctl/examples/aws/out/controlplane.yaml

Retrieve the kubeconfig for the requested cluster

clusterctl alpha phases get-kubeconfig --kubeconfig=<path to management cluster kubeconfig> --provider=aws --cluster-name=test1

This command will write a file named kubeconfig to the current working directory.

Apply the cluster addons to the created cluster

While it would be possible to run this command directly with kubectl, clusterctl is used here since the control plane may not yet be up for the cluster and clusterctl will continue to retry until the control plane becomes available.

clusterctl alpha phases apply-addons -a cmd/clusterctl/examples/aws/out/controlplane.yaml --kubeconfig=kubeconfig

Deploy the Machine object for the worker node

Currently clusterctl does not provide a way to extract just the worker machine from the MachineList in machines.yaml when running individual phases, so this step will need to be done manually. This assumes that a new file worker.yaml was created with just the worker node object defined in machines.yaml

kubectl create -f cmd/clusterctl/examples/aws/out/worker.yaml

To watch for the node to become available:

kubectl --kubeconfig=kubeconfig get nodes -w
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment