Skip to content

Commit 127f8c7

Browse files
authored
build: Add AWS clusterclass example (#162)
1 parent 7152d1f commit 127f8c7

17 files changed

+509
-161
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ repos:
1616
language: system
1717
files: "^docs/"
1818
pass_filenames: false
19+
- id: examples-sync
20+
name: examples-sync
21+
entry: make examples.sync
22+
language: system
23+
files: "^hack/examples/"
24+
pass_filenames: false
1925
- repo: https://github.com/tekwizely/pre-commit-golang
2026
rev: v1.0.0-rc.1
2127
hooks:
@@ -102,7 +108,7 @@ repos:
102108
name: License headers - YAML and Makefiles
103109
stages: [commit]
104110
files: (^Makefile|\.(ya?ml|mk))$
105-
exclude: ^pkg/handlers/.+/embedded/.+\.ya?ml$
111+
exclude: ^(pkg/handlers/.+/embedded|examples)/.+\.ya?ml$
106112
args:
107113
- --license-filepath
108114
- hack/license-header.txt

README.md

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,45 +26,61 @@ make SKIP_BUILD=true dev.run-on-kind
2626
To create the ClusterClass and it's Templates with this runtime extension enabled, run:
2727

2828
```shell
29-
kubectl apply --server-side -f examples/capi-quick-start/capd-cluster-class.yaml
29+
kubectl apply --server-side -f examples/capi-quick-start/docker-cluster-class.yaml
30+
```
31+
32+
If creating an AWS cluster using the example files, you will also need to create a secret with your AWS credentials:
33+
34+
```shell
35+
kubectl apply --server-side -f - <<EOF
36+
apiVersion: v1
37+
kind: Secret
38+
metadata:
39+
name: "aws-quick-start-creds"
40+
namespace: capa-system
41+
stringData:
42+
AccessKeyID: ${AWS_ACCESS_KEY_ID}
43+
SecretAccessKey: ${AWS_SECRET_ACCESS_KEY}
44+
SessionToken: ${AWS_SESSION_TOKEN}
45+
EOF
3046
```
3147

3248
To create a cluster, update `clusterConfig` variable and run:
3349

3450
```shell
35-
kubectl apply --server-side -f examples/capi-quick-start/capd-cluster.yaml
51+
kubectl apply --server-side -f examples/capi-quick-start/docker-cluster.yaml
3652
```
3753

3854
Wait until control plane is ready:
3955

4056
```shell
41-
kubectl wait clusters/capd-quick-start --for=condition=ControlPlaneInitialized --timeout=5m
57+
kubectl wait clusters/docker-quick-start --for=condition=ControlPlaneInitialized --timeout=5m
4258
```
4359

4460
To get the kubeconfig for the new cluster, run:
4561

4662
```shell
47-
clusterctl get kubeconfig capd-quick-start > capd-kubeconfig
63+
clusterctl get kubeconfig docker-quick-start > docker-kubeconfig
4864
```
4965

5066
If you are not on Linux, you will also need to fix the generated kubeconfig's `server`, run:
5167

5268
```shell
53-
kubectl config set-cluster capd-quick-start \
54-
--kubeconfig capd-kubeconfig \
55-
--server=https://$(docker port capd-quick-start-lb 6443/tcp)
69+
kubectl config set-cluster docker-quick-start \
70+
--kubeconfig docker-kubeconfig \
71+
--server=https://$(docker port docker-quick-start-lb 6443/tcp)
5672
```
5773

5874
Wait until all nodes are ready (this indicates that CNI has been deployed successfully):
5975

6076
```shell
61-
kubectl --kubeconfig capd-kubeconfig wait nodes --all --for=condition=Ready --timeout=5m
77+
kubectl --kubeconfig docker-kubeconfig wait nodes --all --for=condition=Ready --timeout=5m
6278
```
6379

6480
Show that Calico is running successfully on the workload cluster:
6581

6682
```shell
67-
kubectl --kubeconfig capd-kubeconfig get daemonsets -n calico-system
83+
kubectl --kubeconfig docker-kubeconfig get daemonsets -n calico-system
6884
```
6985

7086
Deploy kube-vip to provide service load-balancer:
@@ -78,29 +94,29 @@ kubectl create configmap \
7894
--namespace kube-system kubevip \
7995
--from-literal "range-global=${kind_subnet_prefix}100.0-${kind_subnet_prefix}100.20" \
8096
--dry-run=client -oyaml |
81-
kubectl --kubeconfig capd-kubeconfig apply --server-side -n kube-system -f -
97+
kubectl --kubeconfig docker-kubeconfig apply --server-side -n kube-system -f -
8298

8399
helm upgrade kube-vip-cloud-provider kube-vip/kube-vip-cloud-provider --version 0.2.2 \
84100
--install \
85101
--wait --wait-for-jobs \
86102
--namespace kube-system \
87-
--kubeconfig capd-kubeconfig \
103+
--kubeconfig docker-kubeconfig \
88104
--set-string=image.tag=v0.0.6
89105

90106
helm upgrade kube-vip kube-vip/kube-vip --version 0.4.2 \
91107
--install \
92108
--wait --wait-for-jobs \
93109
--namespace kube-system \
94-
--kubeconfig capd-kubeconfig \
110+
--kubeconfig docker-kubeconfig \
95111
--set-string=image.tag=v0.6.0
96112
```
97113

98114
Deploy traefik as a LB service:
99115

100116
```shell
101-
helm --kubeconfig capd-kubeconfig repo add traefik https://helm.traefik.io/traefik
117+
helm --kubeconfig docker-kubeconfig repo add traefik https://helm.traefik.io/traefik
102118
helm repo update &>/dev/null
103-
helm --kubeconfig capd-kubeconfig upgrade --install traefik traefik/traefik \
119+
helm --kubeconfig docker-kubeconfig upgrade --install traefik traefik/traefik \
104120
--version v10.9.1 \
105121
--wait --wait-for-jobs \
106122
--set ports.web.hostPort=80 \
@@ -111,13 +127,13 @@ helm --kubeconfig capd-kubeconfig upgrade --install traefik traefik/traefik \
111127
Watch for traefik LB service to get an external address:
112128

113129
```shell
114-
watch -n 0.5 kubectl --kubeconfig capd-kubeconfig get service/traefik
130+
watch -n 0.5 kubectl --kubeconfig docker-kubeconfig get service/traefik
115131
```
116132

117133
To delete the workload cluster, run:
118134

119135
```shell
120-
kubectl delete cluster capd-quick-start
136+
kubectl delete cluster docker-quick-start
121137
```
122138

123139
Notice that the traefik service is deleted before the cluster is actually finally deleted.

devbox.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"actionlint@latest",
44
55
"clusterctl@latest",
6+
"coreutils@latest",
67
"crane@latest",
78
"envsubst@latest",
89
"findutils@latest",

devbox.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
"source": "devbox-search",
2020
"version": "1.5.1"
2121
},
22+
"coreutils@latest": {
23+
"last_modified": "2023-09-17T10:54:49Z",
24+
"resolved": "github:NixOS/nixpkgs/5148520bfab61f99fd25fb9ff7bfbb50dad3c9db#coreutils",
25+
"source": "devbox-search",
26+
"version": "9.3"
27+
},
2228
"crane@latest": {
2329
"last_modified": "2023-08-08T03:07:33Z",
2430
"resolved": "github:NixOS/nixpkgs/844ffa82bbe2a2779c86ab3a72ff1b4176cec467#crane",
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
apiVersion: cluster.x-k8s.io/v1beta1
2+
kind: ClusterClass
3+
metadata:
4+
labels:
5+
cluster.x-k8s.io/provider: aws
6+
name: aws-quick-start
7+
spec:
8+
controlPlane:
9+
machineInfrastructure:
10+
ref:
11+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
12+
kind: AWSMachineTemplate
13+
name: aws-quick-start-control-plane
14+
ref:
15+
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
16+
kind: KubeadmControlPlaneTemplate
17+
name: aws-quick-start-control-plane
18+
infrastructure:
19+
ref:
20+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
21+
kind: AWSClusterTemplate
22+
name: aws-quick-start
23+
patches:
24+
- external:
25+
discoverVariablesExtension: clusterconfigvars.capi-runtime-extensions
26+
generateExtension: clusterconfigpatch.capi-runtime-extensions
27+
name: cluster-config
28+
- definitions:
29+
- jsonPatches:
30+
- op: add
31+
path: /spec/template/spec/region
32+
valueFrom:
33+
template: |
34+
{{ if .region }}{{ .region }}{{ else }}us-west-2{{ end }}
35+
selector:
36+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
37+
kind: AWSClusterTemplate
38+
matchResources:
39+
infrastructureCluster: true
40+
description: aws region to target for cluster creation
41+
name: region
42+
- definitions:
43+
- jsonPatches:
44+
- op: add
45+
path: /spec/template/spec/identityRef
46+
valueFrom:
47+
template: |
48+
kind: AWSClusterStaticIdentity
49+
name: {{ .builtin.cluster.name }}
50+
selector:
51+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
52+
kind: AWSClusterTemplate
53+
matchResources:
54+
infrastructureCluster: true
55+
description: AWSClusterStaticIdentity identityRef to use when creating the cluster
56+
name: identityRef
57+
variables:
58+
- name: region
59+
schema:
60+
openAPIV3Schema:
61+
default: us-west-2
62+
description: aws region to target for cluster creation
63+
example: us-west-2
64+
type: string
65+
workers:
66+
machineDeployments:
67+
- class: default-worker
68+
template:
69+
bootstrap:
70+
ref:
71+
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
72+
kind: KubeadmConfigTemplate
73+
name: aws-quick-start-worker-bootstraptemplate
74+
infrastructure:
75+
ref:
76+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
77+
kind: AWSMachineTemplate
78+
name: aws-quick-start-worker-machinetemplate
79+
---
80+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
81+
kind: AWSClusterTemplate
82+
metadata:
83+
labels:
84+
cluster.x-k8s.io/provider: aws
85+
name: aws-quick-start
86+
spec:
87+
template:
88+
spec: {}
89+
---
90+
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
91+
kind: KubeadmControlPlaneTemplate
92+
metadata:
93+
labels:
94+
cluster.x-k8s.io/provider: aws
95+
name: aws-quick-start-control-plane
96+
spec:
97+
template:
98+
spec:
99+
kubeadmConfigSpec:
100+
clusterConfiguration:
101+
apiServer:
102+
extraArgs:
103+
cloud-provider: aws
104+
controllerManager:
105+
extraArgs:
106+
cloud-provider: aws
107+
initConfiguration:
108+
nodeRegistration:
109+
kubeletExtraArgs:
110+
cloud-provider: aws
111+
name: '{{ ds.meta_data.local_hostname }}'
112+
joinConfiguration:
113+
nodeRegistration:
114+
kubeletExtraArgs:
115+
cloud-provider: aws
116+
name: '{{ ds.meta_data.local_hostname }}'
117+
---
118+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
119+
kind: AWSMachineTemplate
120+
metadata:
121+
labels:
122+
cluster.x-k8s.io/provider: aws
123+
name: aws-quick-start-control-plane
124+
spec:
125+
template:
126+
spec:
127+
iamInstanceProfile: control-plane.cluster-api-provider-aws.sigs.k8s.io
128+
instanceType: m5.xlarge
129+
---
130+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
131+
kind: AWSMachineTemplate
132+
metadata:
133+
labels:
134+
cluster.x-k8s.io/provider: aws
135+
name: aws-quick-start-worker-machinetemplate
136+
spec:
137+
template:
138+
spec:
139+
iamInstanceProfile: nodes.cluster-api-provider-aws.sigs.k8s.io
140+
instanceType: m5.2xlarge
141+
---
142+
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
143+
kind: KubeadmConfigTemplate
144+
metadata:
145+
labels:
146+
cluster.x-k8s.io/provider: aws
147+
name: aws-quick-start-worker-bootstraptemplate
148+
spec:
149+
template:
150+
spec:
151+
joinConfiguration:
152+
nodeRegistration:
153+
kubeletExtraArgs:
154+
cloud-provider: aws
155+
name: '{{ ds.meta_data.local_hostname }}'
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
apiVersion: cluster.x-k8s.io/v1beta1
2+
kind: Cluster
3+
metadata:
4+
labels:
5+
cluster.x-k8s.io/provider: aws
6+
name: aws-quick-start
7+
spec:
8+
clusterNetwork:
9+
pods:
10+
cidrBlocks:
11+
- 192.168.0.0/16
12+
serviceDomain: cluster.local
13+
services:
14+
cidrBlocks:
15+
- 10.128.0.0/12
16+
topology:
17+
class: aws-quick-start
18+
controlPlane:
19+
replicas: 1
20+
variables:
21+
- name: clusterConfig
22+
value:
23+
addons:
24+
cni:
25+
provider: calico
26+
nfd: {}
27+
version: v1.27.5
28+
workers:
29+
machineDeployments:
30+
- class: default-worker
31+
name: md-0
32+
replicas: 1
33+
---
34+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
35+
kind: AWSClusterStaticIdentity
36+
metadata:
37+
labels:
38+
cluster.x-k8s.io/provider: aws
39+
name: aws-quick-start
40+
spec:
41+
allowedNamespaces:
42+
list:
43+
- default
44+
secretRef: aws-quick-start-creds

0 commit comments

Comments
 (0)