• k8s PersistentVolume hostpath 简单使用


    kubernets host PersistentVolume 测试

    因为yaml 格式的问题 ,我修改为了json

    创建 pv

    pv.json
    {
    "kind": "PersistentVolume",
    "apiVersion": "v1",
    "metadata": {
    "name": "mydemo-pv",
    "labels": {
    "type": "local-dalong"
    }
    },
    "spec": {
    "capacity": {
    "storage": "1Gi"
    },
    "accessModes": [
    "ReadWriteOnce"
    ],
    "hostPath": {
    "path": "/Users/dalong/pvapp"
    }
    }
    }
    
    kubectl apply -f pv.json

    创建pvc

    pvc.json
    {
    "kind": "PersistentVolumeClaim",
    "apiVersion": "v1",
    "metadata": {
    "name": "myclaim"
    },
    "spec": {
    "accessModes": [
    "ReadWriteOnce"
    ],
    "volumeMode": "Filesystem",
    "resources": {
    "requests": {
    "storage": "500Mi"
    }
    },
    "selector": {
    "matchLabels": {
    "type": "local-dalong"
    }
    }
    }
    }
    kubectl apply -f pvc.json

    使用pvc

    app.yml
    
    apiVersion: v1
    kind: Namespace
    metadata:
    name: nginx-app
    labels:
    name: nginxs
    
    ---
    
    apiVersion: v1
    kind: ReplicationController
    metadata:
    name: mynignx
    spec:
    replicas: 1
    selector:
    name: nginx
    template:
    metadata:
    labels:
    name: nginx
    spec:
    containers:
    - name: nginx
    image: nginx
    ports:
    - containerPort: 80
    readinessProbe:
    tcpSocket:
    port: 80
    initialDelaySeconds: 5
    periodSeconds: 10
    livenessProbe:
    tcpSocket:
    port: 80
    initialDelaySeconds: 15
    periodSeconds: 20
    volumeMounts:
    - mountPath: /usr/share/nginx/html
    name: git-volume
    volumes:
    - name: git-volume
    persistentVolumeClaim:
    claimName: myclaim
    ---
    
    apiVersion: v1
    kind: Service
    metadata:
    name: nginx
    spec:
    selector:
    name: nginx
    ports:
    - name: http
    port: 80
    protocol: TCP
    nodePort: 31604
    type: NodePort

    结果



    参考资料

    https://kubernetes.io/docs/concepts/storage/
    https://github.com/rongfengliang/k8s-host-pvdemo

  • 相关阅读:
    Python for Data Science
    Python for Data Science
    Python for Data Science
    团队项目选题报告(I know)
    结对第一次作业——原型设计
    团队展示(I know)
    软件工程实践第二次作业——个人项目实战(数独)
    软件工程实践第一次作业--准备篇
    Java微笔记(9)
    Java微笔记(8)
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/9237832.html
Copyright © 2020-2023  润新知