멀티 클러스터 설정에서 사용자 클러스터 만들기

Anthos clusters on bare metal에서는 사용자 클러스터가 워크로드를 실행하며, 멀티 클러스터 아키텍처에서는 관리자 클러스터가 사용자 클러스터를 만들고 관리합니다.

관리자 클러스터를 만든 후 bmctl create config 명령어를 호출하면 yaml 파일이 생성되고, 이를 수정하여 사용자 클러스터를 정의할 수 있습니다. 구성을 적용하고 사용자 클러스터를 만들려면 Anthos clusters on bare metal 1.7.0 이상 버전에서 bmctl create cluster 명령어를 사용하면 됩니다. bmctl create cluster 명령어로 생성된 사용자 클러스터에 실행 전 검사를 적용할 수 있습니다.

워크로드를 관리자 클러스터와 분리하면 관리자 클러스터에 저장된 SSH 키와 같은 민감한 관리 데이터가 해당 정보에 액세스할 필요가 없는 사용자로부터 보호됩니다. 또한 사용자 클러스터를 서로 분리하면 워크로드에 전체적으로 준수한 보안이 제공됩니다.

기본 요건

  • Cloud Storage에서 최신 bmctl을 다운로드했습니다(gs://anthos-baremetal-release/bmctl/1.7.7/linux-amd64/bmctl).
  • 클러스터 API 서버(controlPlaneVIP)에 대한 액세스 권한이 있으며 작동 중인 관리자 클러스터
  • 관리자 클러스터 노드가 대상 사용자 클러스터의 모든 노드에 네트워크로 연결되어 있습니다.
  • bmctl을 실행하는 워크스테이션은 대상 사용자 클러스터의 모든 노드에 네트워크로 연결되어 있습니다.
  • 사용자 클러스터의 모든 노드에서 루트 또는 SUDO 사용자가 사용할 수 있는 사용자 클러스터를 만드는 데 사용되는 SSH 키
  • 1.7.0 이상 버전에서는 Connect에서 사용할 수 있도록 관리자 클러스터에 연결-등록 서비스 계정이 구성됩니다.

사용자 클러스터 구성 파일 만들기

사용자 클러스터를 만들기 위한 구성 파일은 관리자 클러스터를 만드는 데 사용되는 것과 거의 동일합니다. 유일한 차이점은 로컬 사용자 인증 정보 구성 섹션을 삭제하여 구성이 유효한 Kubernetes 리소스 모음이 된다는 점입니다. 구성 섹션은 파일 상단의 bmctl configuration variables 섹션 아래에 있습니다.

기본적으로 사용자 클러스터는 사용자 클러스터를 관리하는 관리자 클러스터에서 사용자 인증 정보를 상속합니다. 이러한 사용자 인증 정보의 일부 또는 전체를 선택적으로 재정의할 수 있습니다. 자세한 내용은 샘플 사용자 클러스터 구성 파일을 참조하세요.

  1. bmctl create config 명령어로 사용자 클러스터 구성 파일을 만듭니다.

    bmctl create config -c USER_CLUSTER_NAME

    예를 들어 다음을 실행하여 user1이라는 사용자 클러스터의 구성 파일을 만듭니다.

    bmctl create config -c user1

    파일은 bmctl-workspace/user1/user1.yaml에 기록됩니다. 파일의 일반적인 경로는 bmctl-workspace/CLUSTER NAME/CLUSTER_NAME.yaml입니다.

  2. 구성 파일을 다음과 같이 변경하여 수정합니다.

    • 구성에서 로컬 사용자 인증 정보 파일 경로를 삭제합니다.

      ....
        gcrKeyPath: (path to GCR service account key)
        sshPrivateKeyPath: (path to SSH private key, used for node access)
        gkeConnectAgentServiceAccountKeyPath: (path to Connect agent service account key)
        gkeConnectRegisterServiceAccountKeyPath: (path to Hub registration service account key)
        cloudOperationsServiceAccountKeyPath: (path to Cloud Operations service account key)
      ....
      
    • admin 대신 user 클러스터 유형을 지정하도록 구성을 변경합니다.

      ....
      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: user
      ....
      
    • 부하 분산기 VIP 및 주소 풀의 관리자 및 사용자 클러스터 사양이 상호 보완적이며 기존 클러스터와 겹치지 않는지 확인합니다. 부하 분산 및 주소 풀을 지정하는 관리자 및 사용자 클러스터 구성의 샘플 쌍이 아래에 나와 있습니다.

      ....
      # Sample admin cluster config for load balancer and address pools
        loadBalancer:
          vips:
            controlPlaneVIP: 10.200.0.49
            ingressVIP: 10.200.0.50
          addressPools:
          - name: pool1
            addresses:
            - 10.200.0.50-10.200.0.70
      ....
      ....
      # Sample user cluster config for load balancer and address pools
      loadBalancer:
          vips:
            controlPlaneVIP: 10.200.0.71
            ingressVIP: 10.200.0.72
          addressPools:
          - name: pool1
            addresses:
            - 10.200.0.72-10.200.0.90
      ....
      

      나머지 사용자 클러스터 구성 파일은 관리자 클러스터 구성과 동일합니다.

    • 클러스터 노드 및 컨테이너 런타임의 포드 밀도를 지정합니다.

      ....
      # 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: 110
        # containerRuntime specifies which container runtime to use for scheduling containers on nodes.
        # containerd and docker are supported.
        containerRuntime: containerd
      ....
      

      사용자 클러스터의 경우 maxPodsPerNode에 허용되는 값은 32-250입니다. 지정되지 않은 경우 기본값은 110입니다. 클러스터가 생성된 후에는 이 값을 업데이트할 수 없습니다.

      또한 포드 밀도는 클러스터의 사용 가능한 IP 리소스에 따라서도 제한됩니다. 자세한 내용은 포드 네트워킹을 참조하세요.

사용자 클러스터 만들기

bmctl 명령어를 실행하여 사용자 클러스터 구성을 적용하고 클러스터를 만듭니다.

bmctl create cluster -c USER_CLUSTER_NAME --kubeconfig ADMIN_KUBECONFIG

다음을 바꿉니다.

  • USER_CLUSTER_NAME: 이전 섹션에서 만든 클러스터 이름입니다.
  • ADMIN_KUBECONFIG: 관리자 클러스터 kubeconfig 파일의 경로입니다.

예를 들어 사용자 클러스터 이름이 user1이고 관리자 클러스터 kubeconfig 파일의 경로가 kubeconfig bmctl-workspace/admin/admin-kubeconfig인 경우 명령어는 다음과 같습니다.

bmctl create cluster -c user1 --kubeconfig bmctl-workspace/admin/admin-kubeconfig

샘플 전체 사용자 클러스터 구성

다음은 bmctl 명령어로 만든 샘플 사용자 클러스터 구성 파일입니다. 이 샘플 구성에는 자리표시자 클러스터 이름, VIP, 주소가 사용됩니다. 사용 중인 네트워크에서 작동하지 않을 수 있습니다. 사용자 인증 정보는 기본적으로 관리자 클러스터에서 상속됩니다. 사용자 인증 정보를 재정의하려면 configuration variables 섹션에 해당 키 경로를 제공해야 합니다.

# Sample user cluster config:

# ---
# To override default credentials
# 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-user1
---
apiVersion: baremetal.cluster.gke.io/v1
kind: Cluster
metadata:
  name: user1
  namespace: cluster-user1
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: user
  # Anthos cluster version.
  anthosBareMetalVersion: 1.7.7
  # 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: &lt;Redirect URL for the gcloud CLI; optional, default is "http://kubectl.redirect.invalid"&gt;
  #     # 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-user1
spec:
  clusterName: user1
  nodes:
  - address: 10.200.0.5