Skip to content

Commit 082b3e3

Browse files
committed
docs: simplify running examples in README
1 parent f85024a commit 082b3e3

File tree

8 files changed

+82
-44
lines changed

8 files changed

+82
-44
lines changed

README.md

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,18 @@ stringData:
6969
EOF
7070
```
7171

72-
To create an example cluster:
72+
Generate a cluster definition from the file specified in the `--from` flag
73+
and apply the generated resource to actually create the cluster in the API.
74+
For example, the following command will create a Docker cluster with Cilium CNI applied via the Helm addon provider:
7375

7476
```shell
75-
clusterctl generate cluster docker-quick-start-helm-addon-cilium \
76-
--from examples/capi-quick-start/docker-cluster-cilium-helm-addon.yaml \
77+
export CLUSTER_NAME=docker-cluster-cilium-helm-addon
78+
export CLUSTER_FILE=examples/capi-quick-start/docker-cluster-cilium-helm-addon.yaml
79+
```
80+
81+
```shell
82+
clusterctl generate cluster ${CLUSTER_NAME} \
83+
--from ${CLUSTER_FILE} \
7784
--kubernetes-version v1.29.1 \
7885
--worker-machine-count 1 | \
7986
kubectl apply --server-side -f -
@@ -82,36 +89,36 @@ clusterctl generate cluster docker-quick-start-helm-addon-cilium \
8289
Wait until control plane is ready:
8390

8491
```shell
85-
kubectl wait clusters/docker-quick-start-helm-addon-cilium --for=condition=ControlPlaneInitialized --timeout=5m
92+
kubectl wait clusters/${CLUSTER_NAME} --for=condition=ControlPlaneInitialized --timeout=5m
8693
```
8794

8895
To get the kubeconfig for the new cluster, run:
8996

9097
```shell
91-
clusterctl get kubeconfig docker-quick-start-helm-addon-cilium > docker-kubeconfig
98+
clusterctl get kubeconfig ${CLUSTER_NAME} > ${CLUSTER_NAME}.conf
9299
```
93100

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

96103
```shell
97-
kubectl config set-cluster docker-quick-start-helm-addon-cilium \
98-
--kubeconfig docker-kubeconfig \
99-
--server=https://$(docker container port docker-quick-start-helm-addon-cilium-lb 6443/tcp)
104+
kubectl config set-cluster ${CLUSTER_NAME} \
105+
--kubeconfig ${CLUSTER_NAME}.conf \
106+
--server=https://$(docker container port ${CLUSTER_NAME}-lb 6443/tcp)
100107
```
101108

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

104111
```shell
105-
kubectl --kubeconfig docker-kubeconfig wait nodes --all --for=condition=Ready --timeout=5m
112+
kubectl --kubeconfig ${CLUSTER_NAME}.conf wait nodes --all --for=condition=Ready --timeout=5m
106113
```
107114

108115
Show that Cilium is running successfully on the workload cluster:
109116

110117
```shell
111-
kubectl --kubeconfig docker-kubeconfig get daemonsets -n kube-system cilium
118+
kubectl --kubeconfig ${CLUSTER_NAME}.conf get daemonsets -n kube-system cilium
112119
```
113120

114-
Deploy kube-vip to provide service load-balancer:
121+
Deploy kube-vip to provide service load-balancer functionality for Docker clusters:
115122

116123
```shell
117124
helm repo add --force-update kube-vip https://kube-vip.github.io/helm-charts
@@ -122,29 +129,29 @@ kubectl create configmap \
122129
--namespace kube-system kubevip \
123130
--from-literal "range-global=${kind_subnet_prefix}100.0-${kind_subnet_prefix}100.20" \
124131
--dry-run=client -oyaml |
125-
kubectl --kubeconfig docker-kubeconfig apply --server-side -n kube-system -f -
132+
kubectl --kubeconfig ${CLUSTER_NAME}.conf apply --server-side -n kube-system -f -
126133

127134
helm upgrade kube-vip-cloud-provider kube-vip/kube-vip-cloud-provider --version 0.2.2 \
128135
--install \
129136
--wait --wait-for-jobs \
130137
--namespace kube-system \
131-
--kubeconfig docker-kubeconfig \
138+
--kubeconfig ${CLUSTER_NAME}.conf \
132139
--set-string=image.tag=v0.0.6
133140

134141
helm upgrade kube-vip kube-vip/kube-vip --version 0.4.2 \
135142
--install \
136143
--wait --wait-for-jobs \
137144
--namespace kube-system \
138-
--kubeconfig docker-kubeconfig \
145+
--kubeconfig ${CLUSTER_NAME}.conf \
139146
--set-string=image.tag=v0.6.0
140147
```
141148

142149
Deploy traefik as a LB service:
143150

144151
```shell
145-
helm --kubeconfig docker-kubeconfig repo add traefik https://helm.traefik.io/traefik
152+
helm --kubeconfig ${CLUSTER_NAME}.conf repo add traefik https://helm.traefik.io/traefik
146153
helm repo update &>/dev/null
147-
helm --kubeconfig docker-kubeconfig upgrade --install traefik traefik/traefik \
154+
helm --kubeconfig ${CLUSTER_NAME}.conf upgrade --install traefik traefik/traefik \
148155
--version v10.9.1 \
149156
--wait --wait-for-jobs \
150157
--set ports.web.hostPort=80 \
@@ -155,13 +162,13 @@ helm --kubeconfig docker-kubeconfig upgrade --install traefik traefik/traefik \
155162
Watch for traefik LB service to get an external address:
156163

157164
```shell
158-
watch -n 0.5 kubectl --kubeconfig docker-kubeconfig get service/traefik
165+
watch -n 0.5 kubectl --kubeconfig ${CLUSTER_NAME}.conf get service/traefik
159166
```
160167

161168
To delete the workload cluster, run:
162169

163170
```shell
164-
kubectl delete cluster docker-quick-start-helm-addon-cilium
171+
kubectl delete cluster ${CLUSTER_NAME}
165172
```
166173

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

examples/capi-quick-start/aws-cluster-calico-crs.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,15 @@ spec:
5353
- class: default-worker
5454
name: md-0
5555
replicas: ${WORKER_MACHINE_COUNT}
56+
---
57+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
58+
kind: AWSClusterStaticIdentity
59+
metadata:
60+
labels:
61+
cluster.x-k8s.io/provider: aws
62+
name: ${CLUSTER_NAME}
63+
spec:
64+
allowedNamespaces:
65+
list:
66+
- default
67+
secretRef: aws-quick-start-creds

examples/capi-quick-start/aws-cluster-calico-helm-addon.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,15 @@ spec:
5353
- class: default-worker
5454
name: md-0
5555
replicas: ${WORKER_MACHINE_COUNT}
56+
---
57+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
58+
kind: AWSClusterStaticIdentity
59+
metadata:
60+
labels:
61+
cluster.x-k8s.io/provider: aws
62+
name: ${CLUSTER_NAME}
63+
spec:
64+
allowedNamespaces:
65+
list:
66+
- default
67+
secretRef: aws-quick-start-creds

examples/capi-quick-start/aws-cluster-cilium-crs.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,15 @@ spec:
5353
- class: default-worker
5454
name: md-0
5555
replicas: ${WORKER_MACHINE_COUNT}
56+
---
57+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
58+
kind: AWSClusterStaticIdentity
59+
metadata:
60+
labels:
61+
cluster.x-k8s.io/provider: aws
62+
name: ${CLUSTER_NAME}
63+
spec:
64+
allowedNamespaces:
65+
list:
66+
- default
67+
secretRef: aws-quick-start-creds

examples/capi-quick-start/aws-cluster-cilium-helm-addon.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,15 @@ spec:
5353
- class: default-worker
5454
name: md-0
5555
replicas: ${WORKER_MACHINE_COUNT}
56+
---
57+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
58+
kind: AWSClusterStaticIdentity
59+
metadata:
60+
labels:
61+
cluster.x-k8s.io/provider: aws
62+
name: ${CLUSTER_NAME}
63+
spec:
64+
allowedNamespaces:
65+
list:
66+
- default
67+
secretRef: aws-quick-start-creds

examples/capi-quick-start/aws-cluster-identity.yaml

Lines changed: 0 additions & 11 deletions
This file was deleted.

hack/examples/bases/aws/AWSClusterStaticIdentity.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
---
5-
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
5+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta2
66
kind: AWSClusterStaticIdentity
77
metadata:
88
name: "quick-start"

hack/examples/sync.sh

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ mkdir -p "${EXAMPLE_CLUSTERCLASSES_DIR}"
1919
readonly EXAMPLE_CLUSTERS_DIR=examples/capi-quick-start
2020
mkdir -p "${EXAMPLE_CLUSTERS_DIR}"
2121

22-
mkdir -p examples/capi-quick-start
2322
# Sync ClusterClasses (including Templates) and Clusters to separate files.
2423
kustomize build ./hack/examples |
2524
tee \
@@ -68,37 +67,32 @@ kustomize build ./hack/examples |
6867
)' >"${EXAMPLE_CLUSTERCLASSES_DIR}/aws-cluster-class.yaml"
6968
) \
7069
>(
71-
gojq --yaml-input --yaml-output 'select(.metadata.labels["cluster.x-k8s.io/provider"] == "aws"
70+
gojq --yaml-input --yaml-output 'select((.metadata.labels["cluster.x-k8s.io/provider"] == "aws"
7271
and .kind == "Cluster"
7372
and .spec.topology.variables[0].value.addons.cni.provider == "Calico"
7473
and .spec.topology.variables[0].value.addons.cni.strategy == "ClusterResourceSet"
75-
)' >"${EXAMPLE_CLUSTERS_DIR}/aws-cluster-calico-crs.yaml"
74+
) or .kind == "AWSClusterStaticIdentity")' >"${EXAMPLE_CLUSTERS_DIR}/aws-cluster-calico-crs.yaml"
7675
) \
7776
>(
78-
gojq --yaml-input --yaml-output 'select(.metadata.labels["cluster.x-k8s.io/provider"] == "aws"
77+
gojq --yaml-input --yaml-output 'select((.metadata.labels["cluster.x-k8s.io/provider"] == "aws"
7978
and .kind == "Cluster"
8079
and .spec.topology.variables[0].value.addons.cni.provider == "Calico"
8180
and .spec.topology.variables[0].value.addons.cni.strategy == "HelmAddon"
82-
)' >"${EXAMPLE_CLUSTERS_DIR}/aws-cluster-calico-helm-addon.yaml"
81+
) or .kind == "AWSClusterStaticIdentity")' >"${EXAMPLE_CLUSTERS_DIR}/aws-cluster-calico-helm-addon.yaml"
8382
) \
8483
>(
85-
gojq --yaml-input --yaml-output 'select(.metadata.labels["cluster.x-k8s.io/provider"] == "aws"
84+
gojq --yaml-input --yaml-output 'select((.metadata.labels["cluster.x-k8s.io/provider"] == "aws"
8685
and .kind == "Cluster"
8786
and .spec.topology.variables[0].value.addons.cni.provider == "Cilium"
8887
and .spec.topology.variables[0].value.addons.cni.strategy == "ClusterResourceSet"
89-
)' >"${EXAMPLE_CLUSTERS_DIR}/aws-cluster-cilium-crs.yaml"
88+
) or .kind == "AWSClusterStaticIdentity")' >"${EXAMPLE_CLUSTERS_DIR}/aws-cluster-cilium-crs.yaml"
9089
) \
9190
>(
92-
gojq --yaml-input --yaml-output 'select(.metadata.labels["cluster.x-k8s.io/provider"] == "aws"
91+
gojq --yaml-input --yaml-output 'select((.metadata.labels["cluster.x-k8s.io/provider"] == "aws"
9392
and .kind == "Cluster"
9493
and .spec.topology.variables[0].value.addons.cni.provider == "Cilium"
9594
and .spec.topology.variables[0].value.addons.cni.strategy == "HelmAddon"
96-
)' >"${EXAMPLE_CLUSTERS_DIR}/aws-cluster-cilium-helm-addon.yaml"
97-
) \
98-
>(
99-
gojq --yaml-input --yaml-output 'select(.metadata.labels["cluster.x-k8s.io/provider"] == "aws"
100-
and .kind == "AWSClusterStaticIdentity"
101-
)' >"${EXAMPLE_CLUSTERS_DIR}/aws-cluster-identity.yaml"
95+
) or .kind == "AWSClusterStaticIdentity")' >"${EXAMPLE_CLUSTERS_DIR}/aws-cluster-cilium-helm-addon.yaml"
10296
) \
10397
>/dev/null
10498

0 commit comments

Comments
 (0)