deploy categraf as daemonset
This commit is contained in:
parent
258a407deb
commit
bdd288fb28
|
@ -18,6 +18,14 @@ Categraf is a monitoring agent for nightingale/prometheus/m3db/victoriametrics/t
|
|||
go build
|
||||
```
|
||||
|
||||
## Build
|
||||
|
||||
```shell
|
||||
edit k8s/damonset.sh and set namespace (default test) and dry_run to false, then
|
||||
|
||||
cd k8s && sh daemonset.sh install
|
||||
```
|
||||
|
||||
## Test
|
||||
|
||||
```shell
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
---
|
||||
apiVersion: apps/v1
|
||||
kind: DaemonSet
|
||||
metadata:
|
||||
annotations: {}
|
||||
labels:
|
||||
app: n9e
|
||||
component: categraf
|
||||
release: nightingale
|
||||
name: nightingale-categraf
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: n9e
|
||||
component: categraf
|
||||
release: nightingale
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: n9e
|
||||
component: categraf
|
||||
release: nightingale
|
||||
spec:
|
||||
affinity:
|
||||
nodeAffinity:
|
||||
requiredDuringSchedulingIgnoredDuringExecution:
|
||||
nodeSelectorTerms:
|
||||
- matchExpressions:
|
||||
- key: kubernetes.io/os
|
||||
operator: In
|
||||
values:
|
||||
- linux
|
||||
containers:
|
||||
- env:
|
||||
- name: TZ
|
||||
value: Asia/Shanghai
|
||||
- name: HOSTNAME
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
apiVersion: v1
|
||||
fieldPath: spec.nodeName
|
||||
- name: HOSTIP
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
apiVersion: v1
|
||||
fieldPath: status.hostIP
|
||||
- name: HOST_PROC
|
||||
value: /hostfs/proc
|
||||
- name: HOST_SYS
|
||||
value: /hostfs/sys
|
||||
- name: HOST_MOUNT_PREFIX
|
||||
value: /hostfs
|
||||
image: flashcatcloud/categraf:v0.1.3
|
||||
imagePullPolicy: IfNotPresent
|
||||
name: categraf
|
||||
resources: {}
|
||||
terminationMessagePath: /dev/termination-log
|
||||
terminationMessagePolicy: File
|
||||
volumeMounts:
|
||||
- mountPath: /etc/categraf/conf/config.toml
|
||||
name: categraf-config
|
||||
subPath: config.toml
|
||||
- mountPath: /etc/categraf/conf/logs.toml
|
||||
name: categraf-config
|
||||
subPath: logs.toml
|
||||
MOUNTS
|
||||
- mountPath: /var/run/utmp
|
||||
name: hostroutmp
|
||||
readOnly: true
|
||||
- mountPath: /hostfs
|
||||
name: hostrofs
|
||||
readOnly: true
|
||||
- mountPath: /var/run/docker.sock
|
||||
name: docker-socket
|
||||
dnsPolicy: ClusterFirstWithHostNet
|
||||
hostNetwork: true
|
||||
restartPolicy: Always
|
||||
schedulerName: default-scheduler
|
||||
securityContext: {}
|
||||
tolerations:
|
||||
- effect: NoSchedule
|
||||
operator: Exists
|
||||
volumes:
|
||||
- configMap:
|
||||
defaultMode: 420
|
||||
items:
|
||||
- key: config.toml
|
||||
path: config.toml
|
||||
- key: logs.toml
|
||||
path: logs.toml
|
||||
name: categraf-config
|
||||
name: categraf-config
|
||||
VOLUMES
|
||||
- hostPath:
|
||||
path: /
|
||||
type: ""
|
||||
name: hostrofs
|
||||
- hostPath:
|
||||
path: /var/run/utmp
|
||||
type: ""
|
||||
name: hostroutmp
|
||||
- hostPath:
|
||||
path: /var/run/docker.sock
|
||||
type: Socket
|
||||
name: docker-socket
|
|
@ -0,0 +1,68 @@
|
|||
namespace=test
|
||||
|
||||
dry_run=true
|
||||
if [[ $dry_run == true ]]; then
|
||||
dry_run_params="--dry-run=client"
|
||||
else
|
||||
dry_run_params=""
|
||||
fi
|
||||
|
||||
function install() {
|
||||
#config.toml
|
||||
kubectl create cm categraf-config -n $namespace --from-literal=config.toml=../conf/config.toml --from-literal=logs.toml=../conf/logs.toml ${dry_run_params}
|
||||
|
||||
#input.xxx
|
||||
for dir in $(find ../conf/ -maxdepth 1 -type d ! -path "../conf/" )
|
||||
do
|
||||
name=$(echo $dir | sed -e 's/..\/conf\///g' -e 's/\./-/g' -e 's/_/\-/g' -e 's/ //g')
|
||||
relative=$(echo $dir | sed -e 's/\.\.\///g' -e 's/ //g')
|
||||
kubectl create cm $name -n $namespace --from-file=$dir ${dry_run_params}
|
||||
if [[ "X$mount" == "X" ]] ; then
|
||||
mount=$(echo " - mountPath: /etc/categraf/$relative\n name: $name")
|
||||
else
|
||||
mount=$(echo "$mount\n - mountPath: /etc/categraf/$relative\n name: $name")
|
||||
fi
|
||||
if [[ "X$volume" == "X" ]]; then
|
||||
volume=$(echo " - name: $name\n configMap:\n name: $name")
|
||||
else
|
||||
volume=$(echo "$volume\n - name: $name\n configMap:\n name: $name")
|
||||
fi
|
||||
done
|
||||
|
||||
#daemonset
|
||||
sed -e "s#MOUNTS#$mount#g" -e "s#VOLUMES#$volume#g" categraf.tpl | kubectl apply -n $namespace ${dry_run_params} -f -
|
||||
|
||||
}
|
||||
|
||||
function uninstall() {
|
||||
# config.toml
|
||||
kubectl delete cm categraf-config -n $namespace ${dry_run_params}
|
||||
# input.xxx
|
||||
for dir in $(find ../conf/ -maxdepth 1 -type d ! -path "../conf/" )
|
||||
do
|
||||
kubectl delete cm $name -n $namespace
|
||||
done
|
||||
# daemonset
|
||||
kubectl delete ds -n $namespace nightingale-categraf
|
||||
|
||||
}
|
||||
|
||||
## usage
|
||||
function usage() {
|
||||
echo "** install categraf daemonset, default namespace:test, default action with --dry-run=client **"
|
||||
echo "usage: $0 install|uninstall"
|
||||
}
|
||||
|
||||
|
||||
action=$1
|
||||
case $action in
|
||||
"install" )
|
||||
install
|
||||
;;
|
||||
"uninstall" )
|
||||
uninstall
|
||||
;;
|
||||
* )
|
||||
usage
|
||||
;;
|
||||
esac
|
Loading…
Reference in New Issue