Skip to content

Commit df3503b

Browse files
authored
Sample template for Openstack (#24)
* Sample template for Openstack * update readme to point to the openstack sample
1 parent 08dd845 commit df3503b

File tree

3 files changed

+185
-1
lines changed

3 files changed

+185
-1
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,18 @@ Three main pieces are
2929
* For more Azure information go to [CAPZ Getting Started](https://capz.sigs.k8s.io/topics/getting-started.html)
3030
* For more AWS information go to [CAPA Getting Started](https://cluster-api-aws.sigs.k8s.io/)
3131
* For more Nutanix information go to [CAPX Getting Started](https://opendocs.nutanix.com/capx/latest/getting_started/)
32+
* For more OpenStack information go to [CAPO Getting Started](https://cluster-api.sigs.k8s.io/user/quick-start.html)
3233

33-
Cluster API k3s has been tested on AWS, Azure, AzureStackHCI and Nutanix environments.
34+
Cluster API k3s has been tested on AWS, Azure, AzureStackHCI, Nutanix and OpenStack environments.
3435

3536
To try out the Azure flow, fork the repo and look at `samples/azure/azure-setup.sh`.
3637

3738
To try out the AWS flow, fork the repo and look at `samples/aws/aws-setup.sh`.
3839

3940
To try out the Nutanix flow, fork the repo and look at `samples/nutanix/nutanix-setup.sh`.
4041

42+
To try out the OpenStack flow, fork the repo and look at `samples/openstack/setup.sh`.
43+
4144
### Known Issues
4245

4346
## Roadmap
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
2+
kind: KThreesConfigTemplate
3+
metadata:
4+
name: ${CLUSTER_NAME}-md-0
5+
namespace: default
6+
spec:
7+
template:
8+
spec:
9+
---
10+
apiVersion: cluster.x-k8s.io/v1beta1
11+
kind: Cluster
12+
metadata:
13+
name: ${CLUSTER_NAME}
14+
namespace: default
15+
spec:
16+
clusterNetwork:
17+
pods:
18+
cidrBlocks:
19+
- 192.168.0.0/16
20+
serviceDomain: cluster.local
21+
controlPlaneRef:
22+
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
23+
kind: KThreesControlPlane
24+
name: ${CLUSTER_NAME}-control-plane
25+
infrastructureRef:
26+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha5
27+
kind: OpenStackCluster
28+
name: ${CLUSTER_NAME}
29+
---
30+
apiVersion: cluster.x-k8s.io/v1beta1
31+
kind: MachineDeployment
32+
metadata:
33+
name: ${CLUSTER_NAME}-md-0
34+
namespace: default
35+
spec:
36+
clusterName: ${CLUSTER_NAME}
37+
replicas: ${WORKER_MACHINE_COUNT}
38+
selector:
39+
matchLabels: null
40+
template:
41+
spec:
42+
bootstrap:
43+
configRef:
44+
apiVersion: bootstrap.cluster.x-k8s.io/v1beta1
45+
kind: KThreesConfigTemplate
46+
name: ${CLUSTER_NAME}-md-0
47+
clusterName: ${CLUSTER_NAME}
48+
failureDomain: ${OPENSTACK_FAILURE_DOMAIN}
49+
infrastructureRef:
50+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha5
51+
kind: OpenStackMachineTemplate
52+
name: ${CLUSTER_NAME}-md-0
53+
version: ${KUBERNETES_VERSION}
54+
---
55+
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
56+
kind: KThreesControlPlane
57+
metadata:
58+
name: ${CLUSTER_NAME}-control-plane
59+
namespace: default
60+
spec:
61+
infrastructureTemplate:
62+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha5
63+
kind: OpenStackMachineTemplate
64+
name: ${CLUSTER_NAME}-control-plane
65+
replicas: 1
66+
version: ${KUBERNETES_VERSION}
67+
---
68+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha5
69+
kind: OpenStackCluster
70+
metadata:
71+
name: ${CLUSTER_NAME}
72+
namespace: default
73+
spec:
74+
cloudName: ${OPENSTACK_CLOUD}
75+
dnsNameservers:
76+
- ${OPENSTACK_DNS_NAMESERVERS}
77+
externalNetworkId: ${OPENSTACK_EXTERNAL_NETWORK_ID}
78+
identityRef:
79+
kind: Secret
80+
name: k3s-cloud-config
81+
managedSecurityGroups: false
82+
disablePortSecurity: true
83+
nodeCidr: 10.6.0.0/24
84+
---
85+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha6
86+
kind: OpenStackMachineTemplate
87+
metadata:
88+
name: ${CLUSTER_NAME}-control-plane
89+
namespace: default
90+
spec:
91+
template:
92+
spec:
93+
cloudName: ${OPENSTACK_CLOUD}
94+
flavor: ${OPENSTACK_CONTROL_PLANE_MACHINE_FLAVOR}
95+
identityRef:
96+
kind: Secret
97+
name: k3s-cloud-config
98+
image: ${OPENSTACK_IMAGE_NAME}
99+
sshKeyName: ${OPENSTACK_SSH_KEY_NAME}
100+
---
101+
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha5
102+
kind: OpenStackMachineTemplate
103+
metadata:
104+
name: ${CLUSTER_NAME}-md-0
105+
namespace: default
106+
spec:
107+
template:
108+
spec:
109+
cloudName: ${OPENSTACK_CLOUD}
110+
flavor: ${OPENSTACK_NODE_MACHINE_FLAVOR}
111+
identityRef:
112+
kind: Secret
113+
name: k3s-cloud-config
114+
image: ${OPENSTACK_IMAGE_NAME}
115+
sshKeyName: ${OPENSTACK_SSH_KEY_NAME}

samples/openstack/setup.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
if [ -z "${CLUSTER_NAME}" ]; then
2+
echo "please set CLUSTER_NAME"
3+
exit 0
4+
fi
5+
6+
if [ -z "${KUBERNETES_VERSION}" ]; then
7+
echo "please set KUBERNETES_VERSION"
8+
exit 0
9+
fi
10+
11+
## Configure your OpenStack parameters
12+
# https://github.com/kubernetes-sigs/cluster-api-provider-openstack/blob/main/docs/book/src/clusteropenstack/configuration.md
13+
14+
if [ -z "${OPENSTACK_CLOUD}" ] || [ -z "${OPENSTACK_CONTROL_PLANE_MACHINE_FLAVOR}" ] || [ -z "${OPENSTACK_DNS_NAMESERVERS}" ] || [ -z "${OPENSTACK_EXTERNAL_NETWORK_ID}" ] || [ -z "${OPENSTACK_FAILURE_DOMAIN}" ] || [ -z "${OPENSTACK_IMAGE_NAME}" ] || [ -z "${OPENSTACK_NODE_MACHINE_FLAVOR}" ] || [ -z "${OPENSTACK_SSH_KEY_NAME}" ]; then
15+
echo 'Please set KUBERNETES_VERSION, OPENSTACK_CLOUD, OPENSTACK_CONTROL_PLANE_MACHINE_FLAVOR, OPENSTACK_DNS_NAMESERVERS, OPENSTACK_EXTERNAL_NETWORK_ID, OPENSTACK_FAILURE_DOMAIN, OPENSTACK_IMAGE_NAME, OPENSTACK_NODE_MACHINE_FLAVOR, OPENSTACK_SSH_KEY_NAME'
16+
exit 0
17+
fi
18+
19+
## Create a secret for your OpenStack API
20+
21+
if [ -z "${OS_AUTH_URL}" ] || [ -z "${OS_USERNAME}" ] || [ -z "${OS_PASSWORD}" ] || [ -z "${OS_PROJECT_NAME}" ] || [ -z "${OS_USER_DOMAIN_NAME}" ] || [ -z "${OS_PROJECT_DOMAIN_NAME}" ] || [ -z "${OS_REGION_NAME}" ]; thenn
22+
echo 'Please set OS_AUTH_URL, OS_USERNAME, OS_PASSWORD, OS_PROJECT_NAME, OS_USER_DOMAIN_NAME, OS_PROJECT_DOMAIN_NAME, OS_REGION_NAME'
23+
exit 0
24+
fi
25+
26+
kubectl create -f - <<EOF
27+
apiVersion: v1
28+
kind: Secret
29+
metadata:
30+
name: k3s-cloud-config
31+
labels:
32+
clusterctl.cluster.x-k8s.io/move: "true"
33+
stringData:
34+
cacert: ''
35+
clouds.yaml: |
36+
clouds:
37+
openstack:
38+
auth:
39+
auth_url: "${OS_AUTH_URL}"
40+
username: "${OS_USERNAME}"
41+
password: "${OS_PASSWORD}"
42+
project_name: "${OS_PROJECT_NAME}"
43+
user_domain_name: "${OS_USER_DOMAIN_NAME}"
44+
project_domain_name: "${OS_PROJECT_DOMAIN_NAME}"
45+
region_name: "${OS_REGION_NAME}"
46+
interface: "public"
47+
verify: false
48+
identity_api_version: 3
49+
EOF
50+
51+
52+
## Install correctly your cluser-api-k3s provider
53+
54+
export PWD="$(pwd)"
55+
mkdir -p ~/.cluster-api
56+
cat samples/clusterctl.yaml | envsubst > ~/.cluster-api/clusterctl.yaml
57+
58+
clusterctl init --infrastructure openstack --bootstrap k3s --control-plane k3s
59+
60+
kubectl wait --for=condition=Available --timeout=5m -n capi-system deployment/capi-controller-manager
61+
kubectl wait --for=condition=Available --timeout=5m -n capi-k3s-control-plane-system deployment/capi-k3s-control-plane-controller-manager
62+
kubectl wait --for=condition=Available --timeout=5m -n capo-system deployment/capo-controller-manager
63+
kubectl wait --for=condition=Available --timeout=5m -n capi-k3s-bootstrap-system deployment/capi-k3s-bootstrap-controller-manager
64+
65+
clusterctl generate cluster ${CLUSTER_NAME} --from samples/openstack/k3s-template.yaml | kubectl apply -f -
66+

0 commit comments

Comments
 (0)