栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

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

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

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

0 资源类型 Node, Pod, Container, ReplicationController, ReplicaSet, DaemonSet, Job, CronJob, Services, Endpoints,Ingress, PersistentVolume, PersistentVolumeClaim,StorageClass1 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, persistentVolumeClaim3 端口转发 kubectl port-forward fortune 8080:80 注意监听的是localhost:8080,不是0.0.0.0:80804 hostPath 访问node的文件5 persistentVolume ReclaimPolicy策略类型:Retain,Delete,Recycle。6 动态配置 StorageClass

Review

    声明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: {}
    如上yaml文件。因为emptyDir存在于内存中,所以易失。将git仓库中的文件添加到卷。
 volumes:
  - name: html
    gitRepo:
      repository: https://github.com/luksa/kubia-website-example.git
      revision: master
      directory: .
    创建一个hostpath类型的持久化卷PV
apiVersion: v1
kind: PersistentVolume
metadata:
  name: mongodb-pv
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteonce
    - ReadonlyMany
  persistentVolumeReclaimPolicy: Retain
  hostPath:
    path: /tmp/mongodb
    挂在外部存储就是挂在NFS等类型的PV,需要指明服务地址和导出的path。
volumes: 
  - name: mongodb-data 
    nfs: 
      server: 1.2.3.4 
      path: /some/path
    解耦pod和存储设施。需要学会创建PV和PVC。然后在pod中挂在pvc,而不是直接挂pv了。
volumes:
  - name: mongodb-data
    persistentVolumeClaim: 
    claimName: mongodb-pvc
    转载请注明:文章转载自 www.mshxw.com
    本文地址:https://www.mshxw.com/it/730558.html
    我们一直用心在做
    关于我们 文章归档 网站地图 联系我们

    版权所有 (c)2021-2022 MSHXW.COM

    ICP备案号:晋ICP备2021003244-6号