k8s部署InfluxDB
1. 拉取镜像
docker pull influxdb #拉取镜像
docker run -d influxdb:latest #后台运行容器
docker exec -it 89b /bin/bash #进入容器,89b是容器ID的前三位
cd /usr/bin #进入容器后,进入此文件夹
influxd print-config > /home/default.conf #将influxdb的默认配置导出到文件
exit #退出容器
docker cp 89b:/home/default.conf /home/influxdb/default.conf #将容器内的配置文件cp到主机路径
2. 创建configmap
根据配置文件创建configmap
kubectl create configmap influxdb-config --from-file default.conf
3. 创建pv和pvc
apiVersion: v1
kind: PersistentVolume
metadata:
labels:
type: local
app: influxdb
name: influxdb-pv
spec:
storageClassName: influxdb-sc
accessModes:
- ReadWriteMany
capacity:
storage: 20Gi
hostPath:
path: "/home/influxdb/data"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: influxdb-pvc
spec:
storageClassName: influxdb-sc
accessModes:
- ReadWriteMany
resources:
requests:
storage: 20Gi
- 创建deployment
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: influxdb-dp
name: influxdb-dp
spec:
replicas: 1
selector:
matchLabels:
app: influxdb
template:
metadata:
labels:
app: influxdb
spec:
containers:
- name: influxdb
image: influxdb:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8086
volumeMounts:
- name: influxdb-data
mountPath: /var/lib/influxdb
subPath: influxdb
- name: influxdb-config
mountPath: /etc/influxdb
volumes:
- name: influxdb-data
persistentVolumeClaim:
claimName: influxdb-pvc
- name: influxdb-config
configMap:
name: influxdb-config
BUG记录:
pv和pvc都创建成功,但dp显示no such file or directory,说明读取不到主机路径,修改了rancher的配置,加入了/home目录,就可以了。主机看到的和实际pv挂载的路径不一致,实际默认根目录是/data.
- 创建service
apiVersion: v1
kind: Service
metadata:
name: influxdb-svc
spec:
type: NodePort
ports:
- port: 8086
targetPort: 8086
name: influxdb
selector:
app: influxdb
- 验证
apt install influxdb-client
influx -host 10.43.199.10
参考链接:
https://www.cnblogs.com/zhangsi-lzq/p/14457707.html
https://blog.csdn.net/qq_30549833/article/details/92376406
原文地址:https://blog.csdn.net/weixin_39750084/article/details/136684571
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!