Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ To successfully run a Kubernetes cluster in OpenStack, you will need to configur

## Cluster and machines YAML files

After running `examples/generate.sh` the YAML files will be created in `examples/_out` (or your custom output folder). This files contain configuration on what OpenStack elements to use to create the cluster on, and which cluster components to create. However the template is incomplete and needs to be filled in. The following sections explain some more details about what can be configured.
After running `examples/generate.sh` the YAML files will be created in your custom output folder. This files contain configuration on what OpenStack elements to use to create the cluster on, and which cluster components to create. However the template is incomplete and needs to be filled in. The following sections explain some more details about what can be configured.

## Private Network

Expand Down
6 changes: 4 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ For convenience, a script is provided which generates example YAMLs. The generat
```
cd examples
export CLUSTER_NAME=<cluster-name>
./generate.sh [options] <path/to/clouds.yaml> <openstack-cloud> [output folder]
./generate.sh [options] <path/to/clouds.yaml> <openstack-cloud> <output folder> [single/multi-node]
```

`<clouds.yaml>` is a YAML configuration file for Openstack, for more details refer to [OpenStack client configuration files](https://docs.openstack.org/python-openstackclient/latest/configuration/index.html#configuration-files).
Expand All @@ -51,7 +51,9 @@ export CLUSTER_NAME=<cluster-name>
In case your OpenStack cluster endpoint is using SSL and the cert is signed by an unknown CA, a specific CA certificate
can be provided via the cacert field.

`[output folder]` is where the YAML files will be stored, by default it's `_out`.
`<output folder>` is where the YAML files will be stored.

`[single/multi-node]` is for the control plane preference, by default it's `single-node` .

## Manual Modification

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ spec:
pods:
cidrBlocks: ["192.168.0.0/16"]
serviceDomain: "cluster.local"
# multi-node control-plane:
# * Disable the apiServerPort property
# single-node control-plane:
# * Enable the apiServerPort property
apiServerPort: <disable when multi-node control-plane>
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
kind: OpenStackCluster
Expand All @@ -33,12 +28,6 @@ spec:
name: cloud-config
namespace: ${CLUSTER_NAME}
nodeCidr: <node-cidr>
# multi-node control-plane:
# * Enable the following section to use a Loadbalancer
# which is required for multi-node control plane
# single-node control-plane:
# * Disable the following section to deploy a single node
# control plane
managedAPIServerLoadBalancer: true
apiServerLoadBalancerFloatingIP: <loadbalancer floating ip>
apiServerLoadBalancerPort: 6443
Expand All @@ -54,3 +43,4 @@ spec:
managedSecurityGroups: false
disablePortSecurity: true
disableServerTags: true
useOctavia: true
42 changes: 42 additions & 0 deletions examples/cluster/single-node/cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
apiVersion: cluster.x-k8s.io/v1alpha2
kind: Cluster
metadata:
name: ${CLUSTER_NAME}
namespace: ${CLUSTER_NAME}
spec:
clusterNetwork:
services:
cidrBlocks: ["10.96.0.0/12"]
pods:
cidrBlocks: ["192.168.0.0/16"]
serviceDomain: "cluster.local"
apiServerPort: 6443
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
kind: OpenStackCluster
name: ${CLUSTER_NAME}
namespace: ${CLUSTER_NAME}
---
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
kind: OpenStackCluster
metadata:
name: ${CLUSTER_NAME}
namespace: ${CLUSTER_NAME}
spec:
cloudName: $CLOUD
cloudsSecret:
name: cloud-config
namespace: ${CLUSTER_NAME}
nodeCidr: <node-cidr>
managedAPIServerLoadBalancer: false
dnsNameservers: []
# multi-node control-plane:
# * externalNetworkId is required for:
# * creating routers
# * creating floating ips
# * creating load balancer
externalNetworkId: <external-network-id>
managedSecurityGroups: false
disablePortSecurity: true
disableServerTags: true
7 changes: 7 additions & 0 deletions examples/cluster/single-node/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: ${CLUSTER_NAME}
resources:
- cluster.yaml
configurations:
- kustomizeconfig.yaml
6 changes: 6 additions & 0 deletions examples/cluster/single-node/kustomizeconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace:
- kind: Cluster
group: cluster.x-k8s.io
version: v1alpha2
path: spec/infrastructureRef/namespace
create: true
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ spec:
image: <Image Name>
sshKeyName: cluster-api-provider-openstack
availabilityZone: nova
# multi-node control-plane:
# * Disable the floatingIP property
# single-node control-plane:
# * Enable the floatingIP property
#floatingIP: <floating IP>
cloudName: $CLOUD
cloudsSecret:
name: cloud-config
Expand Down Expand Up @@ -77,12 +72,7 @@ spec:
cloud-provider: openstack
cloud-config: /etc/kubernetes/cloud.conf
clusterConfiguration:
# multi-node control-plane:
# * Configure the floating ip of the loadbalancer
# single-node control-plane:
# * Configure the floating ip of the (only) control
# plane node
controlPlaneEndpoint: "<floating ip>:6443"
controlPlaneEndpoint: "<loadbalancer ip>:6443"
kubernetesVersion: 1.15.0
imageRepository: k8s.gcr.io
apiServer:
Expand Down
100 changes: 100 additions & 0 deletions examples/controlplane/single-node/controlplane.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#####################################################
# ${CLUSTER_NAME}-controlplane-0
#####################################################
apiVersion: cluster.x-k8s.io/v1alpha2
kind: Machine
metadata:
name: ${CLUSTER_NAME}-controlplane-0
namespace: ${CLUSTER_NAME}
labels:
cluster.x-k8s.io/control-plane: "true"
cluster.x-k8s.io/cluster-name: "${CLUSTER_NAME}"
spec:
version: ${KUBERNETES_VERSION}
bootstrap:
configRef:
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha2
kind: KubeadmConfig
name: ${CLUSTER_NAME}-controlplane-0
namespace: ${CLUSTER_NAME}
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
kind: OpenStackMachine
name: ${CLUSTER_NAME}-controlplane-0
namespace: ${CLUSTER_NAME}
---
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha2
kind: OpenStackMachine
metadata:
name: ${CLUSTER_NAME}-controlplane-0
namespace: ${CLUSTER_NAME}
spec:
flavor: m1.medium
image: <Image Name>
sshKeyName: cluster-api-provider-openstack
availabilityZone: nova
floatingIP: <floating IP>
cloudName: $CLOUD
cloudsSecret:
name: cloud-config
namespace: ${CLUSTER_NAME}
---
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha2
kind: KubeadmConfig
metadata:
name: ${CLUSTER_NAME}-controlplane-0
namespace: ${CLUSTER_NAME}
spec:
files:
- path: /etc/kubernetes/cloud.conf
owner: root
permissions: "0600"
content: |-
# cloud.conf to communicate with OpenStack
$OPENSTACK_CLOUD_PROVIDER_CONF6
- path: /etc/certs/cacert
owner: root
permissions: "0600"
content: |
$OPENSTACK_CLOUD_CACERT_CONFIG6
ntp:
servers: []
users:
- name: ubuntu
sshAuthorizedKeys:
- "$MACHINE_CONTROLLER_SSH_PUBLIC_FILE_CONTENT"
initConfiguration:
localAPIEndpoint:
advertiseAddress: '{{ ds.ec2_metadata.local_ipv4 }}'
bindPort: 6443
nodeRegistration:
name: '{{ local_hostname }}'
kubeletExtraArgs:
cloud-provider: openstack
cloud-config: /etc/kubernetes/cloud.conf
clusterConfiguration:
controlPlaneEndpoint: "<floating ip of control plane node>:6443"
kubernetesVersion: 1.15.0
imageRepository: k8s.gcr.io
apiServer:
extraArgs:
cloud-provider: openstack
cloud-config: /etc/kubernetes/cloud.conf
extraVolumes:
- name: cloud
hostPath: /etc/kubernetes/cloud.conf
mountPath: /etc/kubernetes/cloud.conf
readOnly: true
controllerManager:
extraArgs:
cloud-provider: openstack
cloud-config: /etc/kubernetes/cloud.conf
extraVolumes:
- name: cloud
hostPath: /etc/kubernetes/cloud.conf
mountPath: /etc/kubernetes/cloud.conf
readOnly: true
- name: cacerts
hostPath: /etc/certs/cacert
mountPath: /etc/certs/cacert
readOnly: true
7 changes: 7 additions & 0 deletions examples/controlplane/single-node/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: ${CLUSTER_NAME}
resources:
- controlplane.yaml
configurations:
- kustomizeconfig.yaml
15 changes: 15 additions & 0 deletions examples/controlplane/single-node/kustomizeconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace:
- kind: Machine
group: cluster.x-k8s.io
version: v1alpha2
path: spec/infrastructureRef/namespace
create: true
- kind: Machine
group: cluster.x-k8s.io
version: v1alpha2
path: spec/bootstrap/configRef/namespace
create: true

commonLabels:
- path: metadata/labels
create: true
48 changes: 38 additions & 10 deletions examples/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ set -o nounset

# Directories.
SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
OUTPUT_DIR=${OUTPUT_DIR:-${SOURCE_DIR}/_out}

# Binaries
ENVSUBST=${ENVSUBST:-envsubst}
Expand All @@ -32,6 +31,7 @@ export KUBERNETES_VERSION="${KUBERNETES_VERSION:-v1.15.0}"
export CONTROL_PLANE_MACHINE_TYPE="${CONTROL_PLANE_MACHINE_TYPE:-m1.medium}"
export NODE_MACHINE_TYPE="${CONTROL_PLANE_MACHINE_TYPE:-m1.medium}"
export SSH_KEY_NAME="${SSH_KEY_NAME:-cluster-api-provider-openstack}"
export CONTROLPLANE="single-node"

# Overwrite flag.
OVERWRITE=0
Expand All @@ -42,7 +42,7 @@ while test $# -gt 0; do
-h|--help)
echo "$SCRIPT - generates input yaml files for Cluster API on OpenStack"
echo " "
echo "$SCRIPT [options] <path/to/clouds.yaml> <cloud> [output folder]"
echo "$SCRIPT [options] <path/to/clouds.yaml> <cloud> <output folder> [single-node/multi-node]"
echo " "
echo "options:"
echo "-h, --help show brief help"
Expand Down Expand Up @@ -83,10 +83,27 @@ else
exit 1
fi

# Check if output folder directory is provided
if [[ -n "${3-}" ]] && [[ $3 != -* ]] && [[ $3 != --* ]]; then
OUTPUT_DIR=$(echo $3 | tr '[:upper:]' '[:lower:]')
else
echo "no output folder provided, use name '_out' by default"
echo "Error: No output folder provided"
echo "You must specify the output folder."
echo ""
exit 1
fi

# Check if correct controlplane preference is given
if [[ -n "${4-}" ]] && [[ $4 != -* ]] && [[ $4 != --* ]]; then
if [[ "$4" == "single-node" || "$4" == "multi-node" ]]; then
export CONTROLPLANE=$4
else
echo "\"${4}\" is not a valid keyword. Use \"single-node\" or \"multi-node\" instead."
echo ""
exit 1
fi
else
echo "Controlplane preference not given, generating samples for \"single-node\" by default"
fi

if [[ ${OVERWRITE} -ne 1 ]] && [[ -d "$OUTPUT_DIR" ]]; then
Expand All @@ -101,7 +118,6 @@ if [[ ${yq_type} == *"Python script"* ]]; then
exit 1
fi


# Outputs.
COMPONENTS_CLUSTER_API_GENERATED_FILE=${SOURCE_DIR}/provider-components/provider-components-cluster-api.yaml
COMPONENTS_KUBEADM_GENERATED_FILE=${SOURCE_DIR}/provider-components/provider-components-kubeadm.yaml
Expand Down Expand Up @@ -190,11 +206,11 @@ else
fi

# Generate cluster resources.
kustomize build "${SOURCE_DIR}/cluster" | envsubst > "${CLUSTER_GENERATED_FILE}"
kustomize build "${SOURCE_DIR}/cluster/${CONTROLPLANE}" | envsubst > "${CLUSTER_GENERATED_FILE}"
echo "Generated ${CLUSTER_GENERATED_FILE}"

# Generate controlplane resources.
kustomize build "${SOURCE_DIR}/controlplane" | envsubst > "${CONTROLPLANE_GENERATED_FILE}"
kustomize build "${SOURCE_DIR}/controlplane/${CONTROLPLANE}" | envsubst > "${CONTROLPLANE_GENERATED_FILE}"
echo "Generated ${CONTROLPLANE_GENERATED_FILE}"

# Generate machinedeployment resources.
Expand All @@ -205,12 +221,24 @@ cp ${SOURCE_DIR}/addons.yaml "${ADDONS_GENERATED_FILE}"
echo "Generated ${ADDONS_GENERATED_FILE}"

# Generate Cluster API provider components file.
kustomize build "github.com/kubernetes-sigs/cluster-api/config/default/?ref=master" > "${COMPONENTS_CLUSTER_API_GENERATED_FILE}"
echo "Generated ${COMPONENTS_CLUSTER_API_GENERATED_FILE}"
CAPI_BRANCH=${CAPI_BRANCH:-"stable"}
if [[ ${CAPI_BRANCH} == "stable" ]]; then
curl -L https://github.com/kubernetes-sigs/cluster-api/releases/download/v0.2.4/cluster-api-components.yaml > "${COMPONENTS_CLUSTER_API_GENERATED_FILE}"
echo "Downloaded ${COMPONENTS_CLUSTER_API_GENERATED_FILE} from cluster-api stable branch - v0.2.4"
else
kustomize build "github.com/kubernetes-sigs/cluster-api/config/default/?ref=${CAPI_BRANCH}" > "${COMPONENTS_CLUSTER_API_GENERATED_FILE}"
echo "Generated ${COMPONENTS_CLUSTER_API_GENERATED_FILE} from cluster-api - ${CAPI_BRANCH}"
fi

# Generate Kubeadm Bootstrap Provider components file.
kustomize build "github.com/kubernetes-sigs/cluster-api-bootstrap-provider-kubeadm//config/default/?ref=master" > "${COMPONENTS_KUBEADM_GENERATED_FILE}"
echo "Generated ${COMPONENTS_KUBEADM_GENERATED_FILE}"
CABPK_BRANCH=${CABPK_BRANCH:-"stable"}
if [[ ${CABPK_BRANCH} == "stable" ]]; then
curl -L https://github.com/kubernetes-sigs/cluster-api-bootstrap-provider-kubeadm/releases/download/v0.1.2/bootstrap-components.yaml > "${COMPONENTS_KUBEADM_GENERATED_FILE}"
echo "Downloaded ${COMPONENTS_KUBEADM_GENERATED_FILE} from cluster-api-bootstrap-provider-kubeadm stable branch - v0.1.2"
else
kustomize build "github.com/kubernetes-sigs/cluster-api-bootstrap-provider-kubeadm/config/default/?ref=${CABPK_BRANCH}" > "${COMPONENTS_KUBEADM_GENERATED_FILE}"
echo "Generated ${COMPONENTS_KUBEADM_GENERATED_FILE} from cluster-api-bootstrap-provider-kubeadm - ${CABPK_BRANCH}"
fi

# Generate OpenStack Infrastructure Provider components file.
kustomize build "${SOURCE_DIR}/../config/default" | envsubst > "${COMPONENTS_OPENSTACK_GENERATED_FILE}"
Expand Down