《Kubernetes in Action》第6章 附加磁盘存储到容器

Volumes: 将磁盘存储连接到容器

  • 0 资源类型 Node, Pod, Container, ReplicationController, ReplicaSet, DaemonSet, Job, CronJob, Services, Endpoints,Ingress, PersistentVolume, PersistentVolumeClaim,StorageClass
  • 1 Volumes的生命周期像pod的一样,只是Volumes中的文件可能在pod和Volumes被移除之后保留下来。Volumes是pod的组成部分。
  • 2 Volumes的类型:emptyDir, hostPath, gitRepo, nfs, gcePersistDisk, awsElasticBlockStore, azureDisk, cinder, cephfs, iscsi, flocker, glusterfs, quobyte, rbd, flexVolume, vsphereVolume, photoPersistentDisk, scaleIO, configMap, secret, downwardAPI, persistentVolumeClaim
  • 3 端口转发 kubectl port-forward fortune 8080:80 注意监听的是localhost:8080,不是0.0.0.0:8080
  • 4 hostPath 访问node的文件
  • 5 persistentVolume ReclaimPolicy策略类型:Retain,Delete,Recycle。
  • 6 动态配置 StorageClass

Review
在这里插入图片描述

  1. 声明volumns,然后在每个container到模板中挂在卷。
apiVersion: v1
kind: Pod
metadata:
  name: fortune
spec:
  containers:
  - image: myorange/fortune
    name: html-generator
    volumeMounts:
    - name: html
      mountPath: /var/htdocs
  - image: nginx:alpine
    name: web-server
    volumeMounts:
    - name: html
      mountPath: /usr/share/nginx/html
      readOnly: true
    ports:
    - containerPort: 80
      protocol: TCP
  volumes:
  - name: html
    emptyDir: {}
  1. 如上yaml文件。因为emptyDir存在于内存中,所以易失。
  2. 将git仓库中的文件添加到卷。
 volumes:
  - name: html
    gitRepo:
      repository: https://github.com/luksa/kubia-website-example.git
      revision: master
      directory: .
  1. 创建一个hostpath类型的持久化卷PV
apiVersion: v1
kind: PersistentVolume
metadata:
  name: mongodb-pv
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
    - ReadOnlyMany
  persistentVolumeReclaimPolicy: Retain
  hostPath:
    path: /tmp/mongodb
  1. 挂在外部存储就是挂在NFS等类型的PV,需要指明服务地址和导出的path。
volumes: 
  - name: mongodb-data 
    nfs: 
      server: 1.2.3.4 
      path: /some/path
  1. 解耦pod和存储设施。需要学会创建PV和PVC。然后在pod中挂在pvc,而不是直接挂pv了。
volumes:
  - name: mongodb-data
    persistentVolumeClaim: 
    claimName: mongodb-pvc
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值