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:]
- Log in to a cluster node.
- Create the hss.yaml file and copy the following content to the file:
{"metadata":{"name":"hss"},"apiVersion":"v1","kind":"Namespace"}
- Run the following command to create a namespace:
kubectl apply -f hss.yaml
- Method 2: generating a kubeconfig file dedicated to HSS
- Create a dedicated namespace and an account for HSS.
- Log in to a cluster node.
- 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"}
- Run the following command to create a namespace and an account:
kubectl apply -f hss-account.yaml
- Generate the kubeconfig file.
- 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
- Run the following command to generate the kubeconfig file named hss_kubeconfig.yaml:
bash gen_kubeconfig.sh
- Create the gen_kubeconfig.sh file and copy the following content to the file:
- Create a dedicated namespace and an account for HSS.
Step 2: Install an Agent in a User-built Cluster on Huawei Cloud
- Log in to the management console.
- In the upper left corner of the page, select a region, click , and choose Security & Compliance > HSS.
- In the navigation pane, choose .
- On the Cluster tab page, click Install Container Agent. The Container Asset Access and Installation slide-out panel is displayed.
- Select Non-CCE cluster (Internet access) and click Configure Now.
- 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.
- Perform the following operations to install the cluster connection component (ANP-agent) and establish a connection between HSS and the cluster:
- In the Container Asset Access and Installation dialog box, click Download a YAML File.
Figure 2 Downloading the YAML file
- Copy the command file to a directory on any node.
- Run the following command to install the cluster connection component (ANP-Agent):
kubectl apply -f proxy-agent.yaml
- 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.
- 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.
- In the Container Asset Access and Installation dialog box, click Download a YAML File.
- Click Next.
- Configure agent parameters. For more information, see Table 2.
- Click OK to start installing the HSS agent.
- In the cluster list, check the cluster status. If the cluster status is Running, the cluster is successfully connected to HSS.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot