From 88249308a0cb1ad99b15755d48e7830fdd63f63e Mon Sep 17 00:00:00 2001 From: Ryler Hockenbury Date: Mon, 25 Feb 2019 22:58:15 -0500 Subject: [PATCH] Add labels to vsphere cloud config (#4275) --- docs/vsphere.md | 9 +++++++-- .../node/templates/vsphere-cloud-config.j2 | 12 +++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/vsphere.md b/docs/vsphere.md index 04fa69293..5b493c576 100644 --- a/docs/vsphere.md +++ b/docs/vsphere.md @@ -14,6 +14,9 @@ After this step you should have: - UUID activated for each VM where Kubernetes will be deployed - A vSphere account with required privileges +If you intend to leverage the [zone and region node labeling](https://kubernetes.io/docs/reference/kubernetes-api/labels-annotations-taints/#failure-domain-beta-kubernetes-io-region), create a tag category for both the zone and region in vCenter. The tags can then be applied at the host, cluster, datacenter, or folder level, and the cloud provider will walk the hierarchy to extract and apply the labels to the Kubernetes nodes. + + ## Kubespray configuration First you must define the cloud provider in `inventory/sample/group_vars/all.yml` and set it to `vsphere`. @@ -34,9 +37,11 @@ Then, in the same file, you need to declare your vCenter credential following th | vsphere_datastore | TRUE | string | | | Datastore name to use | | vsphere_working_dir | TRUE | string | | | Working directory from the view "VMs and template" in the vCenter where VM are placed | | vsphere_scsi_controller_type | TRUE | string | buslogic, pvscsi, parallel | pvscsi | SCSI controller name. Commonly "pvscsi". | -| vsphere_vm_uuid | FALSE | string | | | VM Instance UUID of virtual machine that host K8s master. Can be retrieved from instanceUuid property in VmConfigInfo, or as vc.uuid in VMX file or in `/sys/class/dmi/id/product_serial` (Optional, only used for Kubernetes <= 1.9.2) | +| vsphere_vm_uuid | FALSE | string | | | VM Instance UUID of virtual machine that host K8s master. Can be retrieved from instanceUuid property in VmConfigInfo, or as vc.uuid in VMX file or in `/sys/class/dmi/id/product_serial` (Optional, only used for Kubernetes <= 1.9.2) | | vsphere_public_network | FALSE | string | | Blank | Name of the network the VMs are joined to | -| vsphere_resource_pool | FALSE | string | | Blank | Name of the Resource pool where the VMs are located (Optional, only used for Kubernetes >= 1.9.2) | +| vsphere_resource_pool | FALSE | string | | Blank | Name of the Resource pool where the VMs are located (Optional, only used for Kubernetes >= 1.9.2) | +| vsphere_zone_category | FALSE | string | | | Name of the tag category used to set the `failure-domain.beta.kubernetes.io/zone` label on nodes (Optional, only used for Kubernetes >= 1.12.0) | +| vsphere_region_category | FALSE | string | | | Name of the tag category used to set the `failure-domain.beta.kubernetes.io/region` label on nodes (Optional, only used for Kubernetes >= 1.12.0) | Example configuration diff --git a/roles/kubernetes/node/templates/vsphere-cloud-config.j2 b/roles/kubernetes/node/templates/vsphere-cloud-config.j2 index 53f4cd037..fda0dd199 100644 --- a/roles/kubernetes/node/templates/vsphere-cloud-config.j2 +++ b/roles/kubernetes/node/templates/vsphere-cloud-config.j2 @@ -41,4 +41,14 @@ scsicontrollertype = {{ vsphere_scsi_controller_type }} {% if vsphere_public_network is defined and vsphere_public_network != "" %} [Network] public-network = {{ vsphere_public_network }} -{% endif %} \ No newline at end of file +{% endif %} + +{% if kube_version is version('v1.12.0', '>=') %} +[Labels] +{% if vsphere_zone_category is defined and vsphere_zone_category != "" %} +zone = {{ vsphere_zone_category }} +{% endif %} +{% if vsphere_region_category is defined and vsphere_region_category != "" %} +region = {{ vsphere_region_category }} +{% endif %} +{% endif %}