DaemonSet and HPA
November 9, 2024Less than 1 minute
DaemonSet and HPA
DaemonSet
Through configuration, add daemonSet automatically
Example
Give Node a Label
kubectl label nodes k8s-node1 svc_type=microsvc
Then, in daemonSet configuration, config the nodeSelector
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: fluentd
spec:
selector:
matchLabels:
app: logging
template:
metadata:
labels:
app: logging
id: fluentd
name: fluentd
spec:
nodeSelector:
type: microsvc
containers:
- name: fluentd-es
image: agilestacks/fluentd-elasticsearch:latest
env:
- name: FLUENTD_ARGS
value: -qq
volumeMounts:
- name: containers
mountPath: /var/lib/docker/containers
- name: varlog
mountPath: /varlog
volumes:
- hostPath:
path: /var/lib/docker/containers
name: containers
- hostPath:
path: /var/log
name: varlog
Add label to node
kubectl label no node1 type=microsvc
HPA (Horizontal Pod Autoscaler)
Automatically scale the number of pods by monitoring CPU, memory usage, or custom metrics.
This is generally used with Deployments and is not suitable for objects that cannot be scaled, such as DaemonSets.
The controller checks resource usage metrics every 30 seconds (adjustable with the –horizontal-pod-autoscaler-sync-period option).
kubectl autoscale deploy nginx-deploy --cpu-percent=20 --min=2 --max=5
kubectl get hpa