(作者:陈玓玏)
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: localapp: influxdbname: influxdb-pv
spec:storageClassName: influxdb-scaccessModes:- ReadWriteManycapacity:storage: 20GihostPath:path: "/home/influxdb/data"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:name: influxdb-pvc
spec:storageClassName: influxdb-scaccessModes:- ReadWriteManyresources:requests:storage: 20Gi
- 创建deployment
apiVersion: apps/v1
kind: Deployment
metadata:labels:app: influxdb-dpname: influxdb-dp
spec:replicas: 1selector:matchLabels:app: influxdbtemplate:metadata:labels:app: influxdbspec:containers:- name: influxdbimage: influxdb:latestimagePullPolicy: IfNotPresentports:- containerPort: 8086volumeMounts:- name: influxdb-datamountPath: /var/lib/influxdbsubPath: influxdb- name: influxdb-configmountPath: /etc/influxdbvolumes:- name: influxdb-datapersistentVolumeClaim:claimName: influxdb-pvc- name: influxdb-configconfigMap: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: NodePortports:- port: 8086targetPort: 8086name: influxdbselector: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