(作者:陈玓玏)
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