Kubernetes

This document describes how to deploy the Huatuo collector to a Kubernetes cluster using a DaemonSet.

1. Kubernetes Manifest Deployment

1.1 Download the configuration file

curl -L -o huatuo-bamai.conf https://github.com/ccfos/huatuo/raw/main/huatuo-bamai.conf

1.2 Modify the configuration file

Modify the configuration file for the deployment environment. For example, configure the storage backend and the method used to obtain Pod information. See the Configuration Guide for details.

1.3 Create the ConfigMap

kubectl create configmap huatuo-bamai-config \
  --namespace default \
  --from-file=./huatuo-bamai.conf \
  --dry-run=client -o yaml |
kubectl apply -f -

1.4 Deploy the collector

Download the DaemonSet manifest:

curl -L -o huatuo-daemonset.yaml \
  https://raw.githubusercontent.com/ccfos/huatuo/main/build/huatuo-daemonset.minimal.yaml

Before deploying to production, set the huatuo container resources to this initial baseline:

resources:
  limits:
    cpu: "2"
    memory: 2Gi
  requests:
    cpu: "2"
    memory: 2Gi

Apply the modified manifest:

kubectl apply -f ./huatuo-daemonset.yaml

requests provide scheduling guarantees, while limits are enforced by the Pod cgroup managed by kubelet. Huatuo does not create its own cgroup by default, so it remains under kubepods and can be reclaimed normally after containerd restart or Pod deletion.

These values are an initial baseline with matching requests and limits, so the Pod has Guaranteed QoS. [Runtime] applies only when --enable-cgroup is explicitly passed; do not pass that flag in Kubernetes.

1.5 Verify the deployment

kubectl rollout status daemonset/huatuo \
  --namespace default \
  --timeout=10m

kubectl get pods \
  --namespace default \
  --selector app=huatuo \
  --output wide

kubectl get daemonset huatuo \
  --namespace default \
  --output jsonpath='{.spec.template.spec.containers[?(@.name=="huatuo")].resources}'

After updating huatuo-bamai.conf, rerun section 1.3 to update the ConfigMap, then manually restart the DaemonSet:

kubectl rollout restart daemonset/huatuo --namespace default

2. Helm Deployment

The Helm Chart is located at build/charts/.

2.1 Check the deployment environment

Helm and kubectl must be installed on the management host, which must be able to access the target Kubernetes cluster.

(command -v helm || curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash) && helm version

TARGET_CONTEXT="$(kubectl config get-contexts -o name | sed -n '1p')"
kubectl --context "${TARGET_CONTEXT}" get nodes

Verify that the target Nodes are Ready.

2.2 Prepare the configuration file

Download and modify huatuo-bamai.conf as described in sections 1.1 and 1.2.

2.3 Configure deployment values

Create values-production.yaml:

image:
  repository: <registry-accessible-to-all-nodes>/huatuo-bamai
  tag: "<release-version>"
  pullPolicy: IfNotPresent

resources:
  limits:
    cpu: "2"
    memory: 2Gi
  requests:
    cpu: "2"
    memory: 2Gi

nodeSelector:
  kubernetes.io/os: linux

tolerations:
  - operator: Exists

hostPaths:
  proc: /proc
  sys: /sys
  run: /run
  var: /var
  etc: /etc
  data: /var/log/huatuo/huatuo-local

2.4 Validate the Helm Chart

helm lint ./build/charts \
  -f ./values-production.yaml \
  --set-file config.content=./huatuo-bamai.conf

helm template huatuo ./build/charts \
  --namespace huatuo \
  -f ./values-production.yaml \
  --set-file config.content=./huatuo-bamai.conf \
  >/dev/null

2.5 Deploy the collector

helm upgrade --install huatuo ./build/charts \
  --kube-context "${TARGET_CONTEXT}" \
  --namespace huatuo \
  --create-namespace \
  -f ./values-production.yaml \
  --set-file config.content=./huatuo-bamai.conf \
  --atomic \
  --timeout 10m

2.6 Verify the deployment

helm status huatuo \
  --kube-context "${TARGET_CONTEXT}" \
  --namespace huatuo

kubectl --context "${TARGET_CONTEXT}" \
  --namespace huatuo \
  get daemonset,configmap,pod --output wide

kubectl --context "${TARGET_CONTEXT}" \
  --namespace huatuo \
  rollout status daemonset/huatuo \
  --timeout=10m

Inspect the collector logs:

kubectl --context "${TARGET_CONTEXT}" \
  --namespace huatuo \
  logs \
  --selector app.kubernetes.io/name=huatuo \
  --prefix \
  --tail=100

2.7 Upgrade and roll back

After changing the image version or huatuo-bamai.conf, rerun the command in section 2.5.

List the release history and roll back to a selected revision:

helm history huatuo \
  --kube-context "${TARGET_CONTEXT}" \
  --namespace huatuo

helm rollback huatuo <revision> \
  --kube-context "${TARGET_CONTEXT}" \
  --namespace huatuo \
  --wait \
  --timeout 10m