由于容器产生的文件又不允许有任何丢失,就测试下hostPath持久化存储,

pod在删除后,宿主机上的文件,不会丢失

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

yaml文件:

[k8s@k8s-m1 yaml]$ cat centos-test.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: centos-deployment-test
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: centos-deployment-label
    spec:
      nodeSelector:
        hostname: node_phy
      containers:
      - name: centos1
        image: centos:latest
        ports:
        - containerPort: 80
        imagePullPolicy: Never
        command: ["/bin/sleep","999"]
        volumeMounts:
        - mountPath: /data/logs/
          name: logdir
          subPath: centos1
      - name: centos2
        image: centos:latest
        ports:
        - containerPort: 80
        imagePullPolicy: Never
        command: ["/bin/sleep","999"]
        volumeMounts:
        - mountPath: /data/logs/
          name: logdir
          subPath: centos2
      - name: centos3
        image: centos:latest
        ports:
        - containerPort: 80
        imagePullPolicy: Never
        command: ["/bin/sleep","999"]
        volumeMounts:
        - mountPath: /data/logs/
          name: logdir
          subPath: centos3
      volumes:
      - name: logdir
        #emptyDir: {}
        hostPath:
          path: /data/logs
          type: DirectoryOrCreate

 

宿主机的目录如下

[root@tjwq01-video-live064014069 ~]# cat /data/logs/centos2/centos2
centos2
2
[root@tjwq01-video-live064014069 ~]# cat /data/logs/centos2/centos2
centos2
2
[root@tjwq01-video-live064014069 ~]# ls -lh /data/logs/*
/data/logs/centos1:
total 0
-rw-r--r-- 1 root root 0 Apr 11 17:16 centos1

/data/logs/centos2:
total 8.0K
-rw-r--r-- 1 root root   10 Apr 11 17:20 centos2

/data/logs/centos3:
total 0

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄