Creazione di una workstation amministrativa

Questa pagina spiega come creare la macchina virtuale (VM) della workstation di amministrazione per la prima volta. In questa pagina viene spiegato anche come configurare il daemon Docker della workstation per lavorare con un proxy.

Vedi anche Eseguire l'upgrade di una workstation di amministrazione esistente.

Panoramica

Usi HashiCorp Terraform versione 0.11 per eseguire il provisioning di una macchina virtuale (VM) di amministrazione su una VM in vSphere e utilizzi la workstation di amministrazione per installare GKE On-Prem. Scarica il file della workstation di amministrazione Open Virtual Appliance (OVA) e utilizza Terraform per eseguire il deployment della VM in vSphere.

Prima di iniziare

  1. Scarica l'OVA della workstation di amministrazione.
  2. Leggi la panoramica della workstation di amministrazione.

Deployment dell'OVA della workstation di amministrazione

Per eseguire il deployment dell'OVA, segui questi passaggi:

  1. Salva una delle seguenti configurazioni Terraform, a seconda che utilizzi DHCP o IP statici. Assicurati di salvare entrambi i file TF e TFVARS. Il file TF è la configurazione HCL di Terraform e il file TFVARS dichiara le variabili da utilizzare nella configurazione:

    dhcp.tf

    #########################
    ####### VARIABLES #######
    #########################
    
    # vSphere username
    variable "vsphere_user" { }
    # vSphere password
    variable "vsphere_password" { }
    # vSphere server address
    variable "vsphere_server" { }
    # Install this public key in the created VM
    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 to create this VM in
    variable "datacenter" { }
    # vSphere datastore to create this VM in
    variable "datastore" { }
    # vSphere cluster to create this VM in
    variable "cluster" { }
    # vSphere resource pool to create this VM in
    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 to clone
    variable "vm_template" { }
    # Enable the provided Docker registry. If you use your own registry, set to "false"
    variable "registry_enable" { default = "true" }
    # Username to set for the Docker registry
    variable "registry_username" { default = "gke" }
    # Password to set for the Docker registry
    variable "registry_password" { default = "password" }
    # Optional DNS hostname for the registry's certificate
    variable "registry_dns_hostname" { default = "" }
    
    #########################
    ##### FOR UPGRADING #####
    #########################
    # Path on disk to the htpasswd file
    variable "registry_htpasswd" { default = "" } // filepath
    # Path on disk to the certificate for the Docker registry in the admin workstation
    variable "registry_cert" { default = "" } // filepath
    # Path on disk to the registry's CA
    variable "registry_ca" { default = "" } // filepath
    # Path on disk to the registry's private key
    variable "registry_private_key" { default = "" } // filepath
    
    ##########################
    ##########################
    
    provider "vsphere" {
      version        = "~> 1.5"
      user           = "${var.vsphere_user}"
      password       = "${var.vsphere_password}"
      vsphere_server = "${var.vsphere_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 $${reg_enable} $${reg_username} $${reg_password} $${reg_dns_hostname} $${reg_htpasswd} $${reg_cert} $${reg_private_key} $${reg_ca}
    EOF
      vars = {
        dhcp_ip_config = "${base64encode(data.template_file.dhcp_ip_config.rendered)}"
    
        reg_enable = "${var.registry_enable}"
        reg_username = "${var.registry_username}"
        reg_password = "${var.registry_password}"
        reg_dns_hostname = "${var.registry_dns_hostname}"
    
        reg_htpasswd = ""
        reg_cert = ""
        reg_private_key = ""
        reg_ca = ""
    
        #########################
        ##### FOR UPGRADING #####
        # reg_htpasswd = "${file(var.registry_htpasswd)}"
        # reg_cert = "${file(var.registry_cert)}"
        # reg_private_key = "${file(var.registry_private_key)}"
        # reg_ca = "${file(var.registry_ca)}"
        #########################
      }
    }
    
    ### 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}"
    }

    dhcp.tfvars

    vsphere_user = "administrator@vsphere.local"
    vsphere_password = ""
    # vSphere server IP or DNS name
    vsphere_server = ""
    ssh_public_key_path = "~/.ssh/vsphere_workstation.pub"
    
    vm_name = "admin-workstation"
    
    datastore = ""
    datacenter = ""
    cluster = ""
    resource_pool = ""
    network = "VM Network"
    
    num_cpus = 4
    memory = 8192
    vm_template = "gke-on-prem-admin-appliance-vsphere-1.0.2-gke.3"
    
    # docker registry credentials
    registry_enable = "true"
    registry_username = "gke"
    registry_password = "password"
    registry_dns_hostname = ""
    
    # only needed when re-creating the workstation and you want to
    # reuse registry certs. Each value is a filepath relative to this file.
    # registry_htpasswd=""
    # registry_cert=""
    # registry_ca=""
    # registry_private_key=""

    static-ip.tf

    #########################
    ####### VARIABLES #######
    #########################
    
    # vSphere username
    variable "vsphere_user" { }
    # vSphere password
    variable "vsphere_password" { }
    # vSphere server address
    variable "vsphere_server" { }
    # Install this public key in the created VM
    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 to create this VM in
    variable "datacenter" { }
    # vSphere datastore to create this VM in
    variable "datastore" { }
    # vSphere cluster to create this VM in
    variable "cluster" { }
    # vSphere resource pool to create this VM in
    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 to clone
    variable "vm_template" { }
    # The IP address to assign this this 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" { }
    # Enable the provided Docker registry. If you use your own registry, set to "false"
    variable "registry_enable" { default = "true" }
    # Username to set for the Docker registry
    variable "registry_username" { default = "gke" }
    # Password to set for the Docker registry
    variable "registry_password" { default = "password" }
    # Optional DNS hostname for the registry's certificate
    variable "registry_dns_hostname" { default = "" }
    
    #########################
    ##### FOR UPGRADING #####
    #########################
    # Path on disk to the htpasswd file
    variable "registry_htpasswd" { default = "" } // filepath
    # Path on disk to the certificate for the Docker registry in the admin workstation
    variable "registry_cert" { default = "" } // filepath
    # Path on disk to the registry's CA
    variable "registry_ca" { default = "" } // filepath
    # Path on disk to the registry's private key
    variable "registry_private_key" { default = "" } // filepath
    
    ##########################
    ##########################
    
    provider "vsphere" {
      version        = "~> 1.5"
      user           = "${var.vsphere_user}"
      password       = "${var.vsphere_password}"
      vsphere_server = "${var.vsphere_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 $${reg_enable} $${reg_username} $${reg_password} $${reg_dns_hostname} $${reg_htpasswd} $${reg_cert} $${reg_private_key} $${reg_ca}
    EOF
      vars = {
        static_ip_config = "${base64encode(data.template_file.static_ip_config.rendered)}"
    
        reg_enable = "${var.registry_enable}"
        reg_username = "${var.registry_username}"
        reg_password = "${var.registry_password}"
        reg_dns_hostname = "${var.registry_dns_hostname}"
    
        reg_htpasswd = ""
        reg_cert = ""
        reg_private_key = ""
        reg_ca = ""
    
        ########################
        #### FOR UPGRADING #####
        # reg_htpasswd = "${file(var.registry_htpasswd)}"
        # reg_cert = "${file(var.registry_cert)}"
        # reg_private_key = "${file(var.registry_private_key)}"
        # reg_ca = "${file(var.registry_ca)}"
        ########################
      }
    }
    ##########################
    ### 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}"
    }

    static-ip.tfvars

    vsphere_user = "administrator@vsphere.local"
    vsphere_password = ""
    # vSphere server IP or DNS name
    vsphere_server = ""
    ssh_public_key_path = "~/.ssh/vsphere_workstation.pub"
    
    vm_name = "admin-workstation"
    
    datastore = ""
    datacenter = ""
    cluster = ""
    resource_pool = ""
    network = "VM Network"
    
    num_cpus = 4
    memory = 8192
    vm_template = "gke-on-prem-admin-appliance-vsphere-1.0.2-gke.3"
    
    # XXX.XXX.XXX.XXX
    ipv4_address = "100.115.250.100"
    # Eg 22
    ipv4_netmask_prefix_length = "22"
    # XXX.XXX.XXX.XXX
    ipv4_gateway = "100.115.251.254"
    # comma separated DNS servers
    dns_nameservers = "8.8.8.8,8.8.4.4"
    
    # docker registry credentials
    registry_enable = "true"
    registry_username = "gke"
    registry_password = "password"
    registry_dns_hostname = ""
    
    # only needed when re-creating the workstation and you want to
    # reuse registry certs. Each value is a filepath relative to this file.
    # registry_htpasswd=""
    # registry_cert=""
    # registry_ca=""
    # registry_private_key=""
  2. Crea una coppia chiave-valore SSH in modo da poter eseguire l'autenticazione nella VM della workstation di amministrazione:

    ssh-keygen -t rsa -f ~/.ssh/vsphere_workstation -N ""
  3. Crea una directory per i file terraform:

    mkdir [TERRAFORM_DIR]

    dove [TERRAFORM_DIR] è il percorso di una directory in cui vuoi conservare i tuoi file Terraform.

  4. Copia la configurazione terraform corrispondente alla configurazione della rete host in [TERRAFORM_DIR]/terraform.tf e [TERRAFORM_DIR]/terraform.tfvars.

  5. In terraform.tfvars inserisci i valori per le seguenti variabili, che specificano gli elementi del tuo ambiente vSphere:

    • vsphere_server
    • vspher_user
    • vsphere_password
    • datastore
    • datacenter
    • cluster
    • resource_pool
    • network
    • vm_template (Hai creato questo passaggio in un passaggio precedente eseguendo govc markastemplate).

    Inserisci un valore per vm_name. Si tratta del nome della workstation di amministrazione che stai per creare. Puoi scegliere qualsiasi nome.

    Se utilizzi indirizzi IP statici, inserisci i valori per le seguenti variabili:

    • ipv4_address
    • ipv4_netmask_prefix_length
    • ipv4_gateway
    • dns_nameservers

    Se vuoi utilizzare il Registro di sistema di Docker eseguito nella VM della workstation di amministrazione, imposta registry_enable su "true". Inserisci anche i valori per queste variabili:

    • registry_username
    • registry_password

    Se vuoi avere un nome host DNS per il registro Docker che viene eseguito sulla VM della workstation di amministrazione, inserisci un valore per registry_dns_hostname. Questo è utile se la VM della workstation di amministrazione non ha un indirizzo IP statico.

    Se vuoi utilizzare il tuo registro Docker privato, imposta registry_enable su "false".

  6. Crea la VM della workstation di amministrazione. L'operazione potrebbe richiedere alcuni minuti:

    cd [TERRAFORM_DIR]
    terraform init && terraform apply -auto-approve -input=false

SSH nella workstation di amministrazione

  1. Passa alla directory contenente la configurazione Terraform.

  2. Recupera l'indirizzo IP della VM della workstation di amministrazione:

    terraform output ip_address
  3. Accedi tramite SSH alla VM della workstation di amministrazione utilizzando la chiave generata e l'indirizzo IP:

    ssh -i ~/.ssh/vsphere_workstation ubuntu@$(terraform output ip_address)

    oppure, se vuoi usare solo il suo indirizzo:

    ssh -i ~/.ssh/vsphere_workstation ubuntu@[IP_ADDRESS]

Verifica che la workstation di amministrazione sia configurata correttamente

Verifica che gkectl e docker siano installati:

gkectl version
docker version

Se imposti registry_enable su"true", puoi verificare che le immagini Docker per i componenti GKE On-Prem siano state caricate nel daemon Docker della VM della workstation di amministrazione:

docker images

Il caricamento di tutte le immagini Docker può richiedere quindici minuti.

Infine, puoi verificare che la VM della tua workstation di amministrazione stia eseguendo un Docker Docker:

docker ps

L'output mostra il container che esegue il registro Docker:

IMAGE ...                      COMMAND ...              NAMES
docker-registry:v2.7.1-gke.0   "registry serve /e..."   registry2

Configurazione di Docker per il pull dal proxy

Se la rete viene eseguita dietro un proxy e la VM della workstation di amministrazione esegue un registro di Docker, devi configurare il daemon Docker in esecuzione sulla tua workstation di amministrazione per eseguire il pull delle immagini tramite il proxy:

  1. Raccogli gli indirizzi dei proxy HTTP e HTTPS.

  2. Raccogli gli indirizzi IP e i nomi host di ogni host che devi contattare senza proxy, tra cui:

    • L'indirizzo IP del server vCenter.
    • Gli indirizzi IP di tutti gli host ESXi.
    • Indirizzi IP che intendi configurare sul tuo bilanciatore del carico.
    • L'intervallo 192.168.0.0/16.

    Nella workstation di amministrazione, aggiungi questi indirizzi alla variabile no_proxy:

    printf -v no_proxy '%s,' [ADDRESSES];
    

    Facoltativamente, puoi esportare l'intervallo in una variabile di ambiente per un utilizzo futuro. Tieni presente che le applicazioni e i processi potrebbero utilizzare questa variabile:

    export no_proxy="${no_proxy%,}";
    
  3. Apri il file di configurazione di Docker, archiviato in /root/.docker/config.json, /home/[USER]/.docker/config.json o altrove, a seconda della configurazione.

  4. All'interno di config.json, aggiungi le seguenti righe:

    "proxies": {
    
    "default": {
           "httpProxy": "[HTTP_PROXY]",
           "httpsProxy": "[HTTPS_PROXY]",
           "noProxy": "[ADDRESSES]"
               }
    }

    dove:

    • [HTTP_PROXY] è il tuo proxy HTTP, se ne hai uno.
    • [HTTPS_PROXY] è il tuo proxy HTTPS, se ne hai uno.
    • [ADDRESSES] è un elenco di indirizzi e nomi host delimitati da virgole che devi contattare senza proxy.
  5. Riavvia Docker per rendere effettive le modifiche:

    sudo systemctl restart docker

Risolvere i problemi

Per ulteriori informazioni, consulta la sezione Risoluzione dei problemi.

Limite sessione del provider Terraform vSphere

GKE On-Prem utilizza il provider vSphere di Terraform per richiamare le VM nel tuo ambiente vSphere. Il limite per le sessioni del provider è 1000. L'implementazione corrente non chiude le sessioni attive dopo l'utilizzo. Se hai troppe sessioni in esecuzione, potresti visualizzare errori 503.

Le sessioni vengono chiuse automaticamente dopo 300 secondi.

Sintomi

Se sono in esecuzione troppe sessioni, potrebbe verificarsi il seguente errore:

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
Potenziali cause

Nel tuo ambiente sono in esecuzione troppe sessioni del provider Terraform.

Risoluzione

Attualmente funziona come previsto. Le sessioni vengono chiuse automaticamente dopo 300 secondi. Per ulteriori informazioni, consulta il problema di GitHub #618.

Utilizzo di un proxy per Docker: oauth2: cannot fetch token

Sintomi

Quando utilizzi un proxy ricevi il seguente errore:

oauth2: cannot fetch token: Post https://oauth2.googleapis.com/token: proxyconnect tcp: tls: oversized record received with length 20527
Potenziali cause

È possibile che tu abbia fornito un proxy HTTPS anziché HTTP.

Risoluzione

Nella configurazione Docker, modifica l'indirizzo proxy in http:// anziché in https://.

Verifica della validità delle licenze

Ricorda che devi verificare la validità delle licenze, soprattutto se utilizzi licenze di prova. Se le licenze F5, ESXi dell'host o vCenter sono scadute, potresti riscontrare errori imprevisti.

openssl non può convalidare l'OVA della workstation di amministrazione

Sintomi

L'esecuzione di openssl dgst nel file OVA della workstation di amministrazione non restituisce Verified OK

Potenziali cause

Nel file OVA è presente un problema che impedisce una convalida riuscita.

Risoluzione

Prova a scaricare e a eseguire il deployment dell'OVA della workstation di amministrazione, come indicato nell'articolo Scaricare l'OVA della workstation di amministrazione. Se il problema persiste, contatta Google per ricevere assistenza.

Passaggi successivi

Prima di installare GKE On-Prem, ecco alcune opzioni facoltative di configurazione: