Eigenständige Cluster erstellen

Auf dieser Seite wird beschrieben, wie Sie einen eigenständigen Cluster erstellen. Dabei handelt es sich um einen selbstverwalteten Cluster, der Arbeitslasten ausführt. Eigenständige Cluster verwalten keine anderen Cluster, sodass in ressourcenbeschränkten Szenarien kein separater Administratorcluster ausgeführt werden muss. Außerdem stehen für eigenständige Cluster zwei Installationsprofile zur Auswahl:

  • Standard: Das Standardprofil hat begrenzte Ressourcenanforderungen.
  • Edge: Das Edge-Profil hat deutlich weniger Systemressourcenanforderungen und wird für Edge-Geräte mit hohen Ressourceneinschränkungen empfohlen.

Berücksichtigen Sie vor dem Erstellen eines eigenständigen Clusters den Kompromiss zwischen der Reduzierung der Ressourcen und der allgemeinen Sicherheit. Da eigenständige Cluster sich selbst verwalten, erhöht das Ausführen von Arbeitslasten auf demselben Cluster das Risiko, vertrauliche administrative Daten wie SSH-Schlüssel offenzulegen.

Hinweis

Prüfen Sie Folgendes, bevor Sie einen eigenständigen Cluster erstellen:

  • Die neueste bmctl wird aus Cloud Storage heruntergeladen (gs://anthos-baremetal-release/bmctl/1.8.9/linux-amd64/bmctl).
  • Die Workstation, auf der bmctl ausgeführt wird, hat eine Netzwerkverbindung zu allen Knoten im eigenständigen Zielcluster.
  • Die Workstation, auf der bmctl ausgeführt wird, hat eine Netzwerkverbindung zur VIP der Steuerungsebene des eigenständigen Zielclusters.
  • Der SSH-Schlüssel, der zum Erstellen des eigenständigen Clusters verwendet wird, ist als Root verfügbar oder auf allen Knoten im eigenständigen Zielcluster ist SUDO-Nutzerzugriff verfügbar.
  • Das Connect-Register-Dienstkonto ist für die Verwendung mit Connect konfiguriert.

SELinux aktivieren

Wenn Sie SELinux zum Schutz Ihrer Container aktivieren möchten, muss SELinux auf den Hostmaschinen im Enforced-Modus aktiviert sein, bevor Sie Anthos-Cluster on Bare Metal installieren. SELinux ist auf RHEL- und CentOS-Systemen standardmäßig aktiviert. Wenn SELinux in Ihren Clustern deaktiviert ist oder Sie sich nicht sicher sind, lesen Sie die Informationen zur Aktivierung unter Container mit SELinux sichern.

Anthos-Cluster on Bare Metal unterstützt SELinux nur in RHEL- und CentOS-Systemen.

Eigenständigen Cluster erstellen

Mit dem Befehl bmctl können Sie einen eigenständigen Cluster mit einer einzigen Knotenebene erstellen. Diese Art der Konfiguration reduziert den Ressourcenverbrauch, bietet jedoch keine Hochverfügbarkeit (High Availability, HA) und der resultierende Cluster hat einen einzigen Ausfallpunkt.

Sie können auch einen eigenständigen HA-Cluster erstellen. Wenn ein Knoten im Hochverfügbarkeitsmodus ausfällt, wird er durch andere Knoten ersetzt. Zum Erstellen eines eigenständigen HA-Clusters müssen Sie mindestens drei Knoten für die Steuerungsebene angeben.

Der Befehl bmctl kann normalerweise auf einer separaten Workstation oder auf einem der eigenständigen Clusterknoten ausgeführt werden. Wenn Sie jedoch einen eigenständigen Cluster mit aktiviertem Edge-Profil erstellen und die mindestens erforderlichen Ressourcen konfiguriert haben, empfehlen wir, bmctl auf einer separaten Workstation auszuführen.

In gcloud anmelden

  1. Melden Sie sich in gcloud als Nutzer an:

    gcloud auth application-default login
    

    Sie benötigen die Rolle eines Projektinhabers oder -bearbeiters, um die Features zur automatischen API-Aktivierung und zur Erstellung von Dienstkonten zu verwenden (siehe unten).

    Sie können dem Nutzer auch die folgenden IAM-Rollen hinzufügen:

    • Dienstkontoadministrator
    • Zentraler Dienstkontoadministrator
    • Projekt-IAM-Administrator
    • Compute-Betrachter
    • Service Usage-Administrator

    Wenn Sie bereits ein Dienstkonto mit diesen Rollen haben, führen Sie Folgendes aus:

    export GOOGLE_APPLICATION_CREDENTIALS=JSON_KEY_FILE
    

    Ersetzen Sie JSON_KEY_FILE durch den Pfad zur JSON-Schlüsseldatei Ihres Dienstkontos.

  2. Rufen Sie Ihre Google Cloud-Projekt-ID ab, um sie bei der Clustererstellung zu verwenden:

    export CLOUD_PROJECT_ID=$(gcloud config get-value project)
    

Konfigurationsdatei für eigenständigen Cluster erstellen

Nachdem Sie sich bei gcloud angemeldet und Ihr Projekt eingerichtet haben, können Sie die Cluster-Konfigurationsdatei mit dem Befehl bmctl erstellen. In diesem Beispiel werden alle Dienstkonten automatisch mit dem Befehl bmctl create config erstellt:

bmctl create config -c STANDALONE_CLUSTER_NAME --enable-apis \
    --create-service-accounts --project-id=$CLOUD_PROJECT_ID

Ersetzen Sie Folgendes:

  • STANDALONE_CLUSTER_NAME durch den Namen des eigenständigen Clusters, den Sie erstellen möchten

Beispiel

Mit dem folgenden Befehl wird eine Konfigurationsdatei für einen eigenständigen Cluster namens standalone1 erstellt, der mit der Projekt-ID my-gcp-project verknüpft ist:

bmctl create config -c standalone1 --create-service-accounts --project-id=my-gcp-project

Die Datei wird in bmctl-workspace/standalone1/standalone1.yaml geschrieben.

Als Alternative zum automatischen Aktivieren von APIs und zum Erstellen von Dienstkonten können Sie auch Ihre vorhandenen Dienstkonten angeben, wenn Sie die entsprechenden IAM-Berechtigungen haben. So können Sie die automatische Erstellung des Dienstkontos im vorherigen Schritt im Befehl bmctl überspringen:

bmctl create config -c standalone1

Cluster-Konfigurationsdatei bearbeiten

Nachdem Sie nun die Cluster-Konfigurationsdatei haben, nehmen Sie die folgenden Änderungen vor:

  1. Fügen Sie den privaten SSH-Schlüssel hinzu, um auf die eigenständigen Clusterknoten zuzugreifen:

    # bmctl configuration variables. Because this section is valid YAML but not a valid Kubernetes
    # resource, this section can only be included when using bmctl to
    # create the initial admin/hybrid cluster. Afterwards, when creating user clusters by directly
    # applying the cluster and node pool resources to the existing cluster, you must remove this
    # section.
    gcrKeyPath:
    /bmctl/bmctl-workspace/.sa-keys/my-gcp-project-anthos-baremetal-gcr.json
    sshPrivateKeyPath: /path/to/your/ssh_private_key
    gkeConnectAgentServiceAccountKeyPath: /bmctl/bmctl-workspace/.sa-keys/my-gcp-project-anthos-baremetal-connect.json
    gkeConnectRegisterServiceAccountKeyPath: /bmctl/bmctl-workspace/.sa-keys/my-gcp-project-anthos-baremetal-register.json
    cloudOperationsServiceAccountKeyPath: /bmctl/bmctl-workspace/.sa-keys/my-gcp-project-anthos-baremetal-cloud-ops.json
    
  2. Registrieren Sie Ihre Cluster bei Ihrer Projektflotte mithilfe von Connect.

    • Wenn Sie Ihre Konfigurationsdatei mithilfe der Features der automatischen API-Aktivierung und der Erstellung von Dienstkonten erstellt haben, können Sie diesen Schritt überspringen.
    • Wenn Sie die Konfigurationsdatei erstellt haben, ohne die Features der automatischen API-Aktivierung und Erstellung von Dienstkonten zu verwenden, verweisen Sie auf die heruntergeladenen JSON-Schlüssel in den entsprechenden Feldern gkeConnectAgentServiceAccountKeyPath und gkeConnectRegisterServiceAccountKeyPath der Cluster-Konfigurationsdatei.
  3. Ändern Sie die Konfiguration, um den Clustertyp standalone anstelle von admin anzugeben. Wenn Sie das Edge-Profil aktivieren möchten, um die Ressourcennutzung zu minimieren, geben Sie profile: edge an:

    spec:
      # Cluster type. This can be:
      #   1) admin:  to create an admin cluster. This can later be used to create user clusters.
      #   2) user:   to create a user cluster. Requires an existing admin cluster.
      #   3) hybrid: to create a hybrid cluster that runs admin cluster components and user workloads.
      #   4) standalone: to create a cluster that manages itself, runs user workloads, but does not manage other clusters.
      type: standalone
      # Edge profile minimizes the resource consumption of Anthos clusters on bare metal. It is only available for standalone clusters.
      profile: edge
    
  4. (Optional) Ändern Sie die Konfiguration, um eine Steuerungsebene mit mehreren Knoten und Hochverfügbarkeit festzulegen. Geben Sie eine ungerade Anzahl von Knoten für einen Großteil des Quorums für HA an:

      # Control plane configuration
      controlPlane:
        nodePoolSpec:
          nodes:
          # Control plane node pools. Typically, this is either a single machine
          # or 3 machines if using a high availability deployment.
          - address: 10.200.0.4
          - address: 10.200.0.5
          - address: 10.200.0.6
    

    Wenn Sie vorübergehend eine gerade Anzahl von Knoten haben, während Sie Knoten zur Wartung oder zum Austausch hinzufügen oder entfernen, hält Ihre Bereitstellung HA aufrecht, solange Sie genügend Quorum haben.

  5. Geben Sie die Pod-Dichte der Clusterknoten und die Containerlaufzeit an:

    ....
    # NodeConfig specifies the configuration that applies to all nodes in the cluster.
    nodeConfig:
      # podDensity specifies the pod density configuration.
      podDensity:
        # maxPodsPerNode specifies at most how many pods can be run on a single node.
        maxPodsPerNode: 250
      # containerRuntime specifies which container runtime to use for scheduling containers on nodes.
      # containerd and docker are supported.
      containerRuntime: containerd
    ....
    

    Zulässige Werte für eigenständige Cluster sind maxPodsPerNode und 32-250 für HA-Cluster und 64-250 für Nicht-HA-Cluster. Der Standardwert, wenn nichts angegeben ist, lautet 110. Sobald der Cluster erstellt ist, kann dieser Wert nicht mehr aktualisiert werden.

    Die Pod-Dichte wird auch durch die verfügbaren IP-Ressourcen des Clusters begrenzt. Weitere Informationen finden Sie unter Pod-Netzwerk.

    Wenn Sie das Edge-Profil mit den konfigurierten Mindestressourcenanforderungen aktivieren, empfehlen wir die Verwendung von containerd als Containerlaufzeit.

Eigenständigen Cluster mit der Clusterkonfiguration erstellen

Verwenden Sie den Befehl bmctl, um den eigenständigen Cluster bereitzustellen:

bmctl create cluster -c <var>CLUSTER_NAME</var>

Ersetzen Sie CLUSTER_NAME durch den Namen des Clusters, den Sie im vorherigen Schritt erstellt haben.

Im Folgenden sehen Sie ein Beispiel für den Befehl zum Erstellen eines Clusters mit dem Namen standalone1:

bmctl create cluster -c standalone1

Beispiel für eine vollständige Konfiguration eines eigenständigen Clusters

Das folgende Beispiel zeigt eine Konfigurationsdatei eines eigenständigen Clusters, die mit dem Befehl bmctl erstellt wurde. In dieser Beispielkonfiguration werden Platzhalter-Clusternamen, -VIPs und -Adressen verwendet. Sie funktionieren in Ihrem Netzwerk möglicherweise nicht.

gcrKeyPath: /bmctl/bmctl-workspace/.sa-keys/my-gcp-project-anthos-baremetal-gcr.json
sshPrivateKeyPath: /bmctl/bmctl-workspace/.ssh/id_rsa
gkeConnectAgentServiceAccountKeyPath: /bmctl/bmctl-workspace/.sa-keys/my-gcp-project-anthos-baremetal-connect.json
gkeConnectRegisterServiceAccountKeyPath: /bmctl/bmctl-workspace/.sa-keys/my-gcp-project-anthos-baremetal-register.json
cloudOperationsServiceAccountKeyPath: /bmctl/bmctl-workspace/.sa-keys/my-gcp-project-anthos-baremetal-cloud-ops.json
---
apiVersion: v1
kind: Namespace
metadata:
  name: cluster-standalone1
---
apiVersion: baremetal.cluster.gke.io/v1
kind: Cluster
metadata:
  name: standalone1
  namespace: cluster-standalone1
spec:
  # Cluster type. This can be:
  #   1) admin:  to create an admin cluster. This can later be used to create user clusters.
  #   2) user:   to create a user cluster. Requires an existing admin cluster.
  #   3) hybrid: to create a hybrid cluster that runs admin cluster components and user workloads.
  #   4) standalone: to create a cluster that manages itself, runs user workloads, but does not manage other clusters.
  type: standalone
  # Anthos cluster version.
  anthosBareMetalVersion: 1.8.9
  # GKE connect configuration
  gkeConnect:
    projectID: $GOOGLE_PROJECT_ID
  # Control plane configuration
  controlPlane:
    nodePoolSpec:
      nodes:
      # Control plane node pools. Typically, this is either a single machine
      # or 3 machines if using a high availability deployment.
      - address: 10.200.0.4
  # Cluster networking configuration
  clusterNetwork:
    # Pods specify the IP ranges from which pod networks are allocated.
    pods:
      cidrBlocks:
      - 192.168.0.0/16
    # Services specify the network ranges from which service virtual IPs are allocated.
    # This can be any RFC 1918 range that does not conflict with any other IP range
    # in the cluster and node pool resources.
    services:
      cidrBlocks:
      - 10.96.0.0/20
  # Load balancer configuration
  loadBalancer:
    # Load balancer mode can be either 'bundled' or 'manual'.
    # In 'bundled' mode a load balancer will be installed on load balancer nodes during cluster creation.
    # In 'manual' mode the cluster relies on a manually-configured external load balancer.
    mode: bundled
    # Load balancer port configuration
    ports:
      # Specifies the port the load balancer serves the Kubernetes control plane on.
      # In 'manual' mode the external load balancer must be listening on this port.
      controlPlaneLBPort: 443
    # There are two load balancer virtual IP (VIP) addresses: one for the control plane
    # and one for the L7 Ingress service. The VIPs must be in the same subnet as the load balancer nodes.
    # These IP addresses do not correspond to physical network interfaces.
    vips:
      # ControlPlaneVIP specifies the VIP to connect to the Kubernetes API server.
      # This address must not be in the address pools below.
      controlPlaneVIP: 10.200.0.71
      # IngressVIP specifies the VIP shared by all services for ingress traffic.
      # Allowed only in non-admin clusters.
      # This address must be in the address pools below.
      ingressVIP: 10.200.0.72
    # AddressPools is a list of non-overlapping IP ranges for the data plane load balancer.
    # All addresses must be in the same subnet as the load balancer nodes.
    # Address pool configuration is only valid for 'bundled' LB mode in non-admin clusters.
    addressPools:
    - name: pool1
      addresses:
      # Each address must be either in the CIDR form (1.2.3.0/24)
      # or range form (1.2.3.1-1.2.3.5).
      - 10.200.0.72-10.200.0.90
    # A load balancer node pool can be configured to specify nodes used for load balancing.
    # These nodes are part of the Kubernetes cluster and run regular workloads as well as load balancers.
    # If the node pool config is absent then the control plane nodes are used.
    # Node pool configuration is only valid for 'bundled' LB mode.
    # nodePoolSpec:
    #  nodes:
    #  - address: <Machine 1 IP>
  # Proxy configuration
  # proxy:
  #   url: http://[username:password@]domain
  #   # A list of IPs, hostnames or domains that should not be proxied.
  #   noProxy:
  #   - 127.0.0.1
  #   - localhost
  # Logging and Monitoring
  clusterOperations:
    # Cloud project for logs and metrics.
    projectID: $GOOGLE_PROJECT_ID
    # Cloud location for logs and metrics.
    location: us-central1
    # Whether collection of application logs/metrics should be enabled (in addition to
    # collection of system logs/metrics which correspond to system components such as
    # Kubernetes control plane or cluster management agents).
    # enableApplication: false
  # Storage configuration
  storage:
    # lvpNodeMounts specifies the config for local PersistentVolumes backed by mounted disks.
    # These disks need to be formatted and mounted by the user, which can be done before or after
    # cluster creation.
    lvpNodeMounts:
      # path specifies the host machine path where mounted disks will be discovered and a local PV
      # will be created for each mount.
      path: /mnt/localpv-disk
      # storageClassName specifies the StorageClass that PVs will be created with. The StorageClass
      # is created during cluster creation.
      storageClassName: local-disks
    # lvpShare specifies the config for local PersistentVolumes backed by subdirectories in a shared filesystem.
    # These subdirectories are automatically created during cluster creation.
    lvpShare:
      # path specifies the host machine path where subdirectories will be created on each host. A local PV
      # will be created for each subdirectory.
      path: /mnt/localpv-share
      # storageClassName specifies the StorageClass that PVs will be created with. The StorageClass
      # is created during cluster creation.
      storageClassName: local-shared
      # numPVUnderSharedPath specifies the number of subdirectories to create under path.
      numPVUnderSharedPath: 5
  # NodeConfig specifies the configuration that applies to all nodes in the cluster.
  nodeConfig:
    # podDensity specifies the pod density configuration.
    podDensity:
      # maxPodsPerNode specifies at most how many pods can be run on a single node.
      maxPodsPerNode: 250
    # containerRuntime specifies which container runtime to use for scheduling containers on nodes.
    # containerd and docker are supported.
    containerRuntime: containerd
  # KubeVirt configuration, uncomment this section if you want to install kubevirt to the cluster
  # kubevirt:
  #   # if useEmulation is enabled, hardware accelerator (i.e relies on cpu feature like vmx or svm)
  #   # will not be attempted. QEMU will be used for software emulation.
  #   # useEmulation must be specified for KubeVirt installation
  #   useEmulation: false
  # Authentication; uncomment this section if you wish to enable authentication to the cluster with OpenID Connect.
  # authentication:
  #   oidc:
  #     # issuerURL specifies the URL of your OpenID provider, such as "https://accounts.google.com". The Kubernetes API
  #     # server uses this URL to discover public keys for verifying tokens. Must use HTTPS.
  #     issuerURL: <URL for OIDC Provider; required>
  #     # clientID specifies the ID for the client application that makes authentication requests to the OpenID
  #     # provider.
  #     clientID: <ID for OIDC client application; required>
  #     # clientSecret specifies the secret for the client application.
  #     clientSecret: <Secret for OIDC client application; optional>
  #     # kubectlRedirectURL specifies the redirect URL (required) for the gcloud CLI, such as
  #     # "http://localhost:[PORT]/callback".
  #     kubectlRedirectURL: <Redirect URL for the gcloud CLI; optional, default is "http://kubectl.redirect.invalid">
  #     # username specifies the JWT claim to use as the username. The default is "sub", which is expected to be a
  #     # unique identifier of the end user.
  #     username: <JWT claim to use as the username; optional, default is "sub">
  #     # usernamePrefix specifies the prefix prepended to username claims to prevent clashes with existing names.
  #     usernamePrefix: <Prefix prepended to username claims; optional>
  #     # group specifies the JWT claim that the provider will use to return your security groups.
  #     group: <JWT claim to use as the group name; optional>
  #     # groupPrefix specifies the prefix prepended to group claims to prevent clashes with existing names.
  #     groupPrefix: <Prefix prepended to group claims; optional>
  #     # scopes specifies additional scopes to send to the OpenID provider as a comma-delimited list.
  #     scopes: <Additional scopes to send to OIDC provider as a comma-separated list; optional>
  #     # extraParams specifies additional key-value parameters to send to the OpenID provider as a comma-delimited
  #     # list.
  #     extraParams: <Additional key-value parameters to send to OIDC provider as a comma-separated list; optional>
  #     # proxy specifies the proxy server to use for the cluster to connect to your OIDC provider, if applicable.
  #     # Example: https://user:password@10.10.10.10:8888. If left blank, this defaults to no proxy.
  #     proxy: <Proxy server to use for the cluster to connect to your OIDC provider; optional, default is no proxy>
  #     # deployCloudConsoleProxy specifies whether to deploy a reverse proxy in the cluster to allow Google Cloud
  #     # Console access to the on-premises OIDC provider for authenticating users. If your identity provider is not
  #     # reachable over the public internet, and you wish to authenticate using Google Cloud console, then this field
  #     # must be set to true. If left blank, this field defaults to false.
  #     deployCloudConsoleProxy: <Whether to deploy a reverse proxy for Google Cloud console authentication; optional>
  #     # certificateAuthorityData specifies a Base64 PEM-encoded certificate authority certificate of your identity
  #     # provider. It's not needed if your identity provider's certificate was issued by a well-known public CA.
  #     # However, if deployCloudConsoleProxy is true, then this value must be provided, even for a well-known public
  #     # CA.
  #     certificateAuthorityData: <Base64 PEM-encoded certificate authority certificate of your OIDC provider; optional>
  # Node access configuration; uncomment this section if you wish to use a non-root user
  # with passwordless sudo capability for machine login.
  # nodeAccess:
  #   loginUser: <login user name>
---
# Node pools for worker nodes
apiVersion: baremetal.cluster.gke.io/v1
kind: NodePool
metadata:
  name: node-pool-1
  namespace: cluster-standalone1
spec:
  clusterName: standalone1
  nodes:
  - address: 10.200.0.5
  - address: 10.200.0.6