Skip to content

Commit

Permalink
Working vsphere clusterctl example (kubernetes-sigs#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicaochen authored and k8s-ci-robot committed Jun 1, 2018
0 parents commit e6f34c9
Show file tree
Hide file tree
Showing 6 changed files with 575 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
machines.yaml
cluster.yaml
provider-components.yaml
vsphere_tmp
vsphere_tmp.pub
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Vsphere Example Files
## Contents
* *.yaml files - concrete example files that can be used as is.
* *.yaml.template files - template example files that need values filled in before use.

## Generation
For convenience, a generation script which populates templates where possible.

1. Run the generation script. This wil produce ```provider-components.yaml```
```
./generate-yaml.sh
```
2. Copy machines.yaml.template to machines.yaml and
Manually edit ```terraformVariables``` for machines in machines.yaml
```
cp machines.yaml.template machines.yaml
```

3. Copy cluster.yaml.template to cluster.yaml and
Manually edit ```providerConfig``` for the cluster in cluster.yaml
```
cp cluster.yaml.template cluster.yaml
```

## Manual Modification
You may always manually curate files based on the examples provided.

18 changes: 18 additions & 0 deletions cluster.yaml.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: "cluster.k8s.io/v1alpha1"
kind: Cluster
metadata:
name: test1
spec:
clusterNetwork:
services:
cidrBlocks: ["10.96.0.0/12"]
pods:
cidrBlocks: ["192.168.0.0/16"]
serviceDomain: "cluster.local"
providerConfig:
value:
apiVersion: "vsphereproviderconfig/v1alpha1"
kind: "VsphereClusterProviderConfig"
vsphereUser: ""
vspherePassword: ""
vsphereServer: ""
63 changes: 63 additions & 0 deletions generate-yaml.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/sh
set -e

PROVIDERCOMPONENT_TEMPLATE_FILE=provider-components.yaml.template
PROVIDERCOMPONENT_GENERATED_FILE=provider-components.yaml

MACHINE_CONTROLLER_SSH_PUBLIC_FILE=vsphere_tmp.pub
MACHINE_CONTROLLER_SSH_PUBLIC=
MACHINE_CONTROLLER_SSH_PRIVATE_FILE=vsphere_tmp
MACHINE_CONTROLLER_SSH_PRIVATE=
MACHINE_CONTROLLER_SSH_HOME=~/.ssh/

OVERWRITE=0

SCRIPT=$(basename $0)
while test $# -gt 0; do
case "$1" in
-h|--help)
echo "$SCRIPT - generates input yaml files for Cluster API on vSphere"
echo " "
echo "$SCRIPT [options]"
echo " "
echo "options:"
echo "-h, --help show brief help"
echo "-f, --force-overwrite if file to be generated already exists, force script to overwrite it"
exit 0
;;
-f)
OVERWRITE=1
shift
;;
--force-overwrite)
OVERWRITE=1
shift
;;
*)
break
;;
esac
done

if [ $OVERWRITE -ne 1 ] && [ -f $PROVIDERCOMPONENT_GENERATED_FILE ]; then
echo File $PROVIDERCOMPONENT_GENERATED_FILE already exists. Delete it manually before running this script.
exit 1
fi

if [ ! -f $MACHINE_CONTROLLER_SSH_PRIVATE_FILE ]; then
echo Generate SSH key files fo machine controller
ssh-keygen -t rsa -f $MACHINE_CONTROLLER_SSH_PRIVATE_FILE -N ""
fi

# Copy file to home ssh directory till using vsphere GetIP logic that
# does not assume the file at this location
cp $MACHINE_CONTROLLER_SSH_PUBLIC_FILE $MACHINE_CONTROLLER_SSH_HOME
cp $MACHINE_CONTROLLER_SSH_PRIVATE_FILE $MACHINE_CONTROLLER_SSH_HOME

MACHINE_CONTROLLER_SSH_PUBLIC=$(cat $MACHINE_CONTROLLER_SSH_PUBLIC_FILE|base64 -w0)
MACHINE_CONTROLLER_SSH_PRIVATE=$(cat $MACHINE_CONTROLLER_SSH_PRIVATE_FILE|base64 -w0)

cat $PROVIDERCOMPONENT_TEMPLATE_FILE \
| sed -e "s/\$MACHINE_CONTROLLER_SSH_PUBLIC/$MACHINE_CONTROLLER_SSH_PUBLIC/" \
| sed -e "s/\$MACHINE_CONTROLLER_SSH_PRIVATE/$MACHINE_CONTROLLER_SSH_PRIVATE/" \
> $PROVIDERCOMPONENT_GENERATED_FILE
57 changes: 57 additions & 0 deletions machines.yaml.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
items:
- apiVersion: "cluster.k8s.io/v1alpha1"
kind: Machine
metadata:
generateName: tf-master-
labels:
set: master
spec:
providerConfig:
value:
apiVersion: "vsphereproviderconfig/v1alpha1"
kind: "VsphereMachineProviderConfig"
vsphereMachine: "standard-master"
terraformVariables: [
"datacenter = \"\"",
"datastore = \"\"",
"resource_pool = \"\"",
"network = \"\"",
"num_cpus = \"2\"",
"memory = \"2048\"",
"vm_template = \"\"",
"disk_label = \"\"",
"disk_size = \"\"",
"virtual_machine_domain = \"\"",
]
versions:
kubelet: 1.10.1
controlPlane: 1.10.1
roles:
- Master
- apiVersion: "cluster.k8s.io/v1alpha1"
kind: Machine
metadata:
generateName: tf-node-
spec:
providerConfig:
value:
apiVersion: "vsphereproviderconfig/v1alpha1"
kind: "VsphereMachineProviderConfig"
vsphereMachine: "standard-node"
terraformVariables: [
"datacenter = \"\"",
"datastore = \"\"",
"resource_pool = \"\"",
"network = \"\"",
"num_cpus = \"2\"",
"memory = \"2048\"",
"vm_template = \"\"",
"disk_label = \"\"",
"disk_size = \"\"",
"virtual_machine_domain = \"\"",
]
versions:
kubelet: 1.10.1
controlPlane: 1.10.1
roles:
- Node
Loading

0 comments on commit e6f34c9

Please sign in to comment.