Updated on 2024-09-25 GMT+08:00

Installing an Agent in a User-built Cluster on Huawei Cloud

Scenario

Install the agent on a user-built cluster on Huawei Cloud that can access the SWR image repository. After the configuration is complete, HSS automatically installs the agent on existing cluster nodes, installs the agent on new nodes when the cluster is scaled out, and uninstalls the agent from removed nodes when the cluster is scaled in.

Step 1: Prepare the kubeconfig File

The kubeconfig file specifies the cluster permissions assigned to HSS. The kubeconfig file configured using method 1 contains the cluster administrator permissions, whereas the file generated using method 2 contains only the permissions required by HSS. If you want to minimize HSS permissions, prepare the file using method 2.

  • Method 1: configuring the default kubeconfig file
    The default kubeconfig file is in the $HOME/.kube/config directory. Perform the following operations to create a dedicated namespace for HSS:]
    1. Log in to a cluster node.
    2. Create the hss.yaml file and copy the following content to the file:
      {"metadata":{"name":"hss"},"apiVersion":"v1","kind":"Namespace"}
    3. Run the following command to create a namespace:
      kubectl apply -f hss.yaml
  • Method 2: generating a kubeconfig file dedicated to HSS
    1. Create a dedicated namespace and an account for HSS.
      1. Log in to a cluster node.
      2. Create the hss-account.yaml file and copy the following content to the file:
        {"metadata":{"name":"hss"},"apiVersion":"v1","kind":"Namespace"}{"metadata":{"name":"hss-user","namespace":"hss"},"apiVersion":"v1","kind":"ServiceAccount"}{"metadata":{"name":"hss-user-token","namespace":"hss","annotations":{"kubernetes.io/service-account.name":"hss-user"}},"apiVersion":"v1","kind":"Secret","type":"kubernetes.io/service-account-token"}
      3. Run the following command to create a namespace and an account:
        kubectl apply -f hss-account.yaml
    2. Generate the kubeconfig file.
      1. Create the gen_kubeconfig.sh file and copy the following content to the file:
        #!/bin/bash
        
        KUBE_APISERVER=`kubectl config view  --output=jsonpath='{.clusters[].cluster.server}' | head -n1 `
        CLUSTER_NAME=`kubectl config view -o jsonpath='{.clusters[0].name}'`
        kubectl get secret hss-user-token -n hss -o yaml |grep ca.crt: | awk '{print $2}' |base64 -d >hss_ca_crt
        
        kubectl config set-cluster ${CLUSTER_NAME} --server=${KUBE_APISERVER}  --certificate-authority=hss_ca_crt  --embed-certs=true --kubeconfig=hss_kubeconfig.yaml
        kubectl config set-credentials hss-user --token=$(kubectl describe secret hss-user-token -n hss | awk '/token:/{print $2}') --kubeconfig=hss_kubeconfig.yaml
        kubectl config set-context hss-user@kubernetes --cluster=${CLUSTER_NAME} --user=hss-user --kubeconfig=hss_kubeconfig.yaml
        kubectl config use-context hss-user@kubernetes --kubeconfig=hss_kubeconfig.yaml
      2. Run the following command to generate the kubeconfig file named hss_kubeconfig.yaml:
        bash gen_kubeconfig.sh

Step 2: Install an Agent in a User-built Cluster on Huawei Cloud

  1. Log in to the management console.
  2. In the upper left corner of the page, select a region, click , and choose Security & Compliance > HSS.
  3. In the navigation pane, choose Installation & Configuration > Container Install & Config.
  4. On the Cluster tab page, click Install Container Agent. The Container Asset Access and Installation slide-out panel is displayed.
  5. Select Non-CCE cluster (Internet access) and click Configure Now.
  6. Configure cluster access information and click Generate Command. For more information, see Table 1.

    Figure 1 Configuring cluster access information
    Table 1 Access parameters

    Parameter

    Description

    Cluster Name

    Name of the cluster to be connected.

    Provider

    Service provider of the cluster. Currently, the clusters of the following service providers are supported:

    • Alibaba Cloud
    • Tencent Cloud
    • AWS
    • Azure
    • User-built
    • On-premises IDC

    KubeConfig

    Add and upload the kubeconfig file configured as required in Step 1: Prepare the kubeconfig File.

    Context

    After the kubeconfig file is uploaded, HSS automatically parses the context.

    Validity Period

    After the kubeconfig file is uploaded, HSS automatically parses the validity period. You can also specify a time before the final validity period. After the specified validity period expires, you need to connect to the asset again.

  7. Perform the following operations to install the cluster connection component (ANP-agent) and establish a connection between HSS and the cluster:

    1. In the Container Asset Access and Installation dialog box, click Download a YAML File.
      Figure 2 Downloading the YAML file
    2. Copy the command file to a directory on any node.
    3. Run the following command to install the cluster connection component (ANP-Agent):
      kubectl apply -f proxy-agent.yaml
    4. Run the following command to check whether the cluster connection component (ANP-agent) is successfully installed:
      kubectl get pods -n hss | grep proxy-agent

      If the command output shown in Figure 3 is displayed, the cluster connection component (ANP-agent) is successfully installed.

      Figure 3 ANP-Agent installed
    5. Run the following command to check whether the cluster is connected to HSS:
      for a in $(kubectl get pods -n hss| grep proxy-agent | cut -d ' ' -f1); do kubectl -n hss logs $a | grep 'Start serving';done

      If the command output shown in Figure 4 is displayed, the cluster is connected to HSS.

      Figure 4 Cluster connected to HSS

  8. Click Next.
  9. Configure agent parameters. For more information, see Table 2.

    Table 2 Agent parameters

    Parameter

    Description

    Configuration Rules

    Select an agent configuration rule.

    • Default Rule: Select this if the sock address of your container runtime is a common address. By default, the agent will be installed on nodes having no taints.
    • Custom: Select this rule if the sock address of your container runtime is not a common address or needs to be modified, or if you only want to install the agent on specific nodes.
    NOTE:
    • If the sock address of your container runtime is incorrect, some HSS functions may be unavailable after the cluster is connected to HSS.
    • You are advised to select all runtime types.

    (Optional) Advanced Configuration

    This parameter can be set if Custom is selected for Configuration Rules.

    Click to expand all advanced configuration items.

    • Enabling auto upgrade agent

      Configure whether to enable automatic agent upgrade. If it is enabled, HSS automatically upgrades the agent to the latest version between 00:00 to 06:00 every day to provide you with better services.

    • Node Selector Configuration

      Click Reference Node Label to select the label of the nodes where the agent is to be installed. If this parameter is not specified, the agent will be installed on all nodes having no taints by default.

    • Tolerance Configuration

      If the taint tag is selected in Node Selector Configuration and the agent needs to be installed on the taint node, you can click Reference Node Taint and configure taint toleration.

  10. Click OK to start installing the HSS agent.
  11. In the cluster list, check the cluster status. If the cluster status is Running, the cluster is successfully connected to HSS.