# If you want to use a resource pool you've configured yourself, export this variable:
export GOVC_RESOURCE_POOL=[VSPHERE_CLUSTER]/Resources/[VSPHERE_RESOURCE_POOL]
# If you want to use vSphere's default resource pool, export this variable instead:
export GOVC_RESOURCE_POOL=[VSPHERE_CLUSTER]/Resources
其中:
[VCENTER_SERVER_ADDRESS] 是您的 vCenter Server 的 IP 地址或主机名。
[VCENTER_SERVER_USERNAME] 是在 vCenter Server 上拥有管理员角色或同等权限的帐号的用户名。
# vCenter Server username
vcenter_user = "administrator@vsphere.local"
# vCenter Server password
vcenter_password = ""
# vCenter Server IP or hostname
vcenter_server = ""
# Path in which the admin workstation's VM's public key should be saved
ssh_public_key_path = "~/.ssh/vsphere_workstation.pub"
# Hostname for the VM
vm_name = "admin-workstation"
# vSphere datastore to use for storage
datastore = ""
# vSphere datacenter in which to create the VM
datacenter = ""
# vSphere cluster in which to create the VM
cluster = ""
# vSphere resource pool in which to create VM, if you are using a non-default resource pool
# If you are using the default resource pool, provide a value like "CLUSTER-NAME/Resources"
resource_pool = ""
# vSphere network to use for the VM
network = "VM Network"
# Number of CPUs for this VM. Recommended minimum 4.
num_cpus = 4
# Memory in MB for this VM. Recommended minimum 8192.
memory = 8192
# The VM template (OVA) to clone. Change the version if you imported a different version of the OVA.
vm_template = "gke-on-prem-admin-appliance-vsphere-1.1.2-gke.0"
terraform.tf
#########################
####### VARIABLES #######
#########################
# The following variables are declared in the accompanying TFVARS file
# vCenter Server username
variable "vcenter_user" { }
# vCenter Server password
variable "vcenter_password" { }
# vCenter Server address
variable "vcenter_server" { }
# Path in which the VM's public key should be saved
variable "ssh_public_key_path" { default = "~/.ssh/vsphere_workstation.pub" }
# vSphere network to use for the VM
variable "network" { default = "VM Network"}
# Hostname for the VM
variable "vm_name" { default = "vsphere-workstation" }
# vSphere datacenter in which to create the admin workstation VM
variable "datacenter" { }
# vSphere datastore to use for storage
variable "datastore" { }
# vSphere cluster in which to create the VM
variable "cluster" { }
# vSphere resource pool in which to create the VM
variable "resource_pool" { }
# Number of CPUs for this VM. Recommended minimum 4.
variable "num_cpus" { default = 4 }
# Memory in MB for this VM. Recommended minimum 8192.
variable "memory" { default = 8192 }
# The VM template (OVA) to clone
variable "vm_template" { }
##########################
##########################
provider "vsphere" {
version = "~> 1.5"
user = "${var.vcenter_user}"
password = "${var.vcenter_password}"
vcenter_server = "${var.vcenter_server}"
# if you have a self-signed cert
allow_unverified_ssl = true
}
### vSphere Data ###
data "vsphere_datastore" "datastore" {
name = "${var.datastore}"
datacenter_id = "${data.vsphere_datacenter.dc.id}"
}
data "vsphere_datacenter" "dc" {
name = "${var.datacenter}"
}
data "vsphere_compute_cluster" "cluster" {
name = "${var.cluster}"
datacenter_id = "${data.vsphere_datacenter.dc.id}"
}
data "vsphere_resource_pool" "pool" {
name = "${var.resource_pool}"
datacenter_id = "${data.vsphere_datacenter.dc.id}"
}
data "vsphere_network" "network" {
name = "${var.network}"
datacenter_id = "${data.vsphere_datacenter.dc.id}"
}
data "vsphere_virtual_machine" "template_from_ovf" {
name = "${var.vm_template}"
datacenter_id = "${data.vsphere_datacenter.dc.id}"
}
data "template_file" "dhcp_ip_config" {
template = <<EOF
network:
version: 2
ethernets:
ens192:
dhcp4: true
EOF
}
data "template_file" "user_data" {
template = <<EOF
#cloud-config
apt:
primary:
- arches: [default]
uri: http://us-west1.gce.archive.ubuntu.com/ubuntu/
write_files:
- path: /etc/netplan/99-dhcp.yaml
permissions: '0644'
encoding: base64
content: |
$${dhcp_ip_config}
runcmd:
- netplan apply
- /var/lib/gke/guest-startup.sh
EOF
vars = {
dhcp_ip_config = "${base64encode(data.template_file.dhcp_ip_config.rendered)}"
}
}
### vSphere Resources ###
resource "vsphere_virtual_machine" "vm" {
name = "${var.vm_name}"
resource_pool_id = "${data.vsphere_resource_pool.pool.id}"
datastore_id = "${data.vsphere_datastore.datastore.id}"
num_cpus = "${var.num_cpus}"
memory = "${var.memory}"
guest_id = "${data.vsphere_virtual_machine.template_from_ovf.guest_id}"
enable_disk_uuid = "true"
scsi_type = "${data.vsphere_virtual_machine.template_from_ovf.scsi_type}"
network_interface {
network_id = "${data.vsphere_network.network.id}"
adapter_type = "${data.vsphere_virtual_machine.template_from_ovf.network_interface_types[0]}"
}
wait_for_guest_net_timeout = 15
nested_hv_enabled = false
cpu_performance_counters_enabled = false
disk {
label = "disk0"
size = "${max(50, data.vsphere_virtual_machine.template_from_ovf.disks.0.size)}"
eagerly_scrub = "${data.vsphere_virtual_machine.template_from_ovf.disks.0.eagerly_scrub}"
thin_provisioned = "${data.vsphere_virtual_machine.template_from_ovf.disks.0.thin_provisioned}"
}
cdrom {
client_device = true
}
vapp {
properties = {
hostname = "${var.vm_name}"
public-keys = "${file(var.ssh_public_key_path)}"
user-data = "${base64encode(data.template_file.user_data.rendered)}"
}
}
clone {
template_uuid = "${data.vsphere_virtual_machine.template_from_ovf.id}"
}
}
output "ip_address" {
value = "${vsphere_virtual_machine.vm.default_ip_address}"
}
静态 IP
点击展开箭头以显示用于静态 IP 地址的 Terraform 文件
terraform.tfvars
# vCenter Server username
vcenter_user = "administrator@vsphere.local"
# vCenter Server password
vcenter_password = ""
# vCenter Server IP or hostname
vcenter_server = ""
# Path in which the admin workstation's VM's public key should be saved
ssh_public_key_path = "~/.ssh/vsphere_workstation.pub"
# Hostname for the VM
vm_name = "admin-workstation"
# vSphere datastore to use for storage
datastore = ""
# vSphere datacenter in which to create the VM
datacenter = ""
# vSphere cluster in which to create the VM
cluster = ""
# vSphere resource pool in which to create VM, if you are using a non-default resource pool
# If you are using the default resource pool, provide a value like "CLUSTER-NAME/Resources"
resource_pool = ""
# vSphere network to use for the VM
network = "VM Network"
# Number of CPUs for this VM. Recommended minimum 4.
num_cpus = 4
# Memory in MB for this VM. Recommended minimum 8192.
memory = 8192
# The VM template (OVA) to clone. Change the version if you imported a different version of the OVA.
vm_template = "gke-on-prem-admin-appliance-vsphere-1.1.2-gke.0"
################################################
# Static IP settings #
################################################
# An IPv4 static IP for the admin workstataion; for example, 100.115.250.100
ipv4_address = "100.115.250.100"
# The netmask prefix length to use; for example, 22
ipv4_netmask_prefix_length = "22"
# The IPv4 gateway the admin workstation should use; for example, 100.115.251.254
ipv4_gateway = "100.115.251.254"
# Comma-delimited DNS servers
dns_nameservers = "8.8.8.8,8.8.4.4"
terraform.tf
#########################
####### VARIABLES #######
#########################
# The following variables are declared in the accompanying TFVARS file
# vCenter Server username
variable "vcenter_user" { }
# vCenter Server password
variable "vcenter_password" { }
# vCenter Server address
variable "vcenter_server" { }
# Path in which the VM's public key should be saved
variable "ssh_public_key_path" { default = "~/.ssh/vsphere_workstation.pub" }
# vSphere network to use for the VM
variable "network" { default = "VM Network"}
# Hostname for the VM
variable "vm_name" { default = "vsphere-workstation" }
# vSphere datacenter in which to create the admin workstation VM
variable "datacenter" { }
# vSphere datastore to use for storage
variable "datastore" { }
# vSphere cluster in which to create the VM
variable "cluster" { }
# vSphere resource pool in which to create the VM
variable "resource_pool" { }
# Number of CPUs for this VM. Recommended minimum 4.
variable "num_cpus" { default = 4 }
# Memory in MB for this VM. Recommended minimum 8192.
variable "memory" { default = 8192 }
# The VM template (OVA) to clone
variable "vm_template" { }
# The IP address to assign to the VM
variable "ipv4_address" { }
# Netmask prefix length
variable "ipv4_netmask_prefix_length" { }
# Default gateway to use
variable "ipv4_gateway" { }
# DNS resolvers to use
variable "dns_nameservers" { }
##########################
##########################
provider "vsphere" {
version = "~> 1.5"
user = "${var.vcenter_user}"
password = "${var.vcenter_password}"
vcenter_server = "${var.vcenter_server}"
# if you have a self-signed cert
allow_unverified_ssl = true
}
### vSphere Data ###
data "vsphere_datastore" "datastore" {
name = "${var.datastore}"
datacenter_id = "${data.vsphere_datacenter.dc.id}"
}
data "vsphere_datacenter" "dc" {
name = "${var.datacenter}"
}
data "vsphere_compute_cluster" "cluster" {
name = "${var.cluster}"
datacenter_id = "${data.vsphere_datacenter.dc.id}"
}
data "vsphere_resource_pool" "pool" {
name = "${var.resource_pool}"
datacenter_id = "${data.vsphere_datacenter.dc.id}"
}
data "vsphere_network" "network" {
name = "${var.network}"
datacenter_id = "${data.vsphere_datacenter.dc.id}"
}
data "vsphere_virtual_machine" "template_from_ovf" {
name = "${var.vm_template}"
datacenter_id = "${data.vsphere_datacenter.dc.id}"
}
##########################
### IF USING STATIC IP ###
##########################
data "template_file" "static_ip_config" {
template = <<EOF
network:
version: 2
ethernets:
ens192:
dhcp4: no
dhcp6: no
addresses: ["${var.ipv4_address}/${var.ipv4_netmask_prefix_length}"]
gateway4: ${var.ipv4_gateway}
nameservers:
addresses: [${var.dns_nameservers}]
EOF
}
data "template_file" "user_data" {
template = <<EOF
#cloud-config
apt:
primary:
- arches: [default]
uri: http://us-west1.gce.archive.ubuntu.com/ubuntu/
write_files:
- path: /tmp/static-ip.yaml
permissions: '0644'
encoding: base64
content: |
$${static_ip_config}
runcmd:
- /var/lib/gke/guest-startup.sh
EOF
vars = {
static_ip_config = "${base64encode(data.template_file.static_ip_config.rendered)}"
}
}
##########################
### IF USING STATIC IP ###
##########################
### vSphere Resources ###
resource "vsphere_virtual_machine" "vm" {
name = "${var.vm_name}"
resource_pool_id = "${data.vsphere_resource_pool.pool.id}"
datastore_id = "${data.vsphere_datastore.datastore.id}"
num_cpus = "${var.num_cpus}"
memory = "${var.memory}"
guest_id = "${data.vsphere_virtual_machine.template_from_ovf.guest_id}"
enable_disk_uuid = "true"
scsi_type = "${data.vsphere_virtual_machine.template_from_ovf.scsi_type}"
network_interface {
network_id = "${data.vsphere_network.network.id}"
adapter_type = "${data.vsphere_virtual_machine.template_from_ovf.network_interface_types[0]}"
}
wait_for_guest_net_timeout = 15
nested_hv_enabled = false
cpu_performance_counters_enabled = false
disk {
label = "disk0"
size = "${max(50, data.vsphere_virtual_machine.template_from_ovf.disks.0.size)}"
eagerly_scrub = "${data.vsphere_virtual_machine.template_from_ovf.disks.0.eagerly_scrub}"
thin_provisioned = "${data.vsphere_virtual_machine.template_from_ovf.disks.0.thin_provisioned}"
}
cdrom {
client_device = true
}
vapp {
properties = {
hostname = "${var.vm_name}"
public-keys = "${file(var.ssh_public_key_path)}"
user-data = "${base64encode(data.template_file.user_data.rendered)}"
}
}
clone {
template_uuid = "${data.vsphere_virtual_machine.template_from_ovf.id}"
}
}
output "ip_address" {
value = "${vsphere_virtual_machine.vm.default_ip_address}"
}
创建 SSH 公钥
创建 SSH 公钥,以便从本地笔记本电脑或工作站通过 SSH 连接到管理员工作站。在基于 Linux 的操作系统上,您可以使用 ssh-keygen:
Error connecting to CIS REST endpoint: Login failed: body:
{"type":"com.vmware.vapi.std.errors.service_unavailable","value":
{"messages":[{"args":["1000","1000"],"default_message":"Sessions count is
limited to 1000. Existing sessions are 1000.",
"id":"com.vmware.vapi.endpoint.failedToLoginMaxSessionCountReached"}]}},
status: 503 Service Unavailable
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2022-05-22。"],[],[]]