• 13.kubernetes之pv,pvc,configmap(带补充实例)


    管理存储是管理计算的一个明显问题。PersistentVolume子系统为用户和管理员提供了一个API,用于抽象如何根据消费方式提供存储的详细信息。为此,我们引入了两个新的API资源:PersistentVolumePersistentVolumeClaim

    PersistentVolume(PV)是群集中由管理员配置的一块存储。它是集群中的资源,就像节点是集群资源一样。PV是容量插件,如Volumes,但其生命周期独立于使用PV的任何单个pod。此API对象捕获存储实现的详细信息,包括NFS,iSCSI或特定于云提供程序的存储系统。

    注意 pv 不是一个namespace资源  pv是跨namespace的共享对象,pvc是有namespace特征的

    PersistentVolumeClaim(PVC)是由用户进行存储的请求。它类似于一个吊舱。Pod消耗节点资源,PVC消耗PV资源。Pod可以请求特定级别的资源(CPU和内存)。声明可以请求特定的大小和访问模式(例如,可以mounted once read/write or many times read-only)。

    虽然PersistentVolumeClaims允许用户使用抽象存储资源,但是PersistentVolumes对于不同的问题,用户通常需要具有不同属性(例如性能)。群集管理员需要能够提供各种PersistentVolumes不同的方式,而不仅仅是大小和访问模式,而不会让用户了解这些卷的实现方式。对于这些需求,有StorageClass 资源。

    创建PV(使用nfs方式或者local)这里使用nfs方式 手动供给方式很low

    安装配置nfs服务器
    [root@nlp-node1 3]# yum install nfs-utils rpcbind -y 已加载插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.huaweicloud.com * updates: mirrors.huaweicloud.com 软件包 1:nfs-utils-1.3.0-0.61.el7.x86_64 已安装并且是最新版本 软件包 rpcbind-0.2.0-47.el7.x86_64 已安装并且是最新版本 无须任何处理 --------------------------------------------------- [root@nlp-node1 3]# vim /etc/exports [root@nlp-node1 3]# cat /etc/exports /kube_pv *(rw,sync,all_squash) [root@nlp-node1 3]# systemctl start nfs.service rpcbind.service [root@nlp-node1 3]# mkdir -pv /kube_pv mkdir: 已创建目录 "/kube_pv" [root@nlp-node1 3]# chown nfsnobody /kube_pv -R

    创建pv

    [root@master pvc]# cat pv.ymal 
    apiVersion: v1
    kind: PersistentVolume
    metadata:
    name: pv-test
    namespace: default
    spec:
    capacity:
    storage: 5Gi
    volumeMode: Filesystem
    accessModes:
    - ReadWriteOnce
    persistentVolumeReclaimPolicy: Recycle
    storageClassName: slow
    nfs:
    path: /kube_pv
    server: 10.24.2.125

    [root@master pvc]# kubectl create -f pv.ymal

    [root@master pvc]# kubectl describe pv 
    Name: pv-test
    Labels: <none>
    Annotations: <none>
    Finalizers: [kubernetes.io/pv-protection]
    StorageClass: slow
    Status: Available
    Claim: 
    Reclaim Policy: Recycle
    Access Modes: RWO
    VolumeMode: Filesystem
    Capacity: 5Gi
    Node Affinity: <none>
    Message: 
    Source:
    Type: NFS (an NFS mount that lasts the lifetime of a pod)
    Server: 10.24.2.125
    Path: /kube_pv
    ReadOnly: false
    Events: <none>
    [root@master pvc]# cat pv.ymal 
    apiVersion: v1
    kind: PersistentVolume
    metadata:
    name: pv-test
    namespace: default
    spec:
    capacity:
    storage: 5Gi
    volumeMode: Filesystem
    accessModes:
    - ReadWriteOnce
    persistentVolumeReclaimPolicy: Recycle
    storageClassName: slow
    nfs:
    path: /kube_pv
    server: 10.24.2.125

    创建pvc

    [root@master pvc]# cat pvc.ymal 
    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
    name: myclaim
    labels:
    song: lele
    spec:
    accessModes:
    - ReadWriteOnce
    volumeMode: Filesystem
    volumeName: pv-test
    resources:
    limits:
    storage: 2Gi
    requests:
    storage: 2Gi
    storageClassName: slow
    selector:
    matchLabels:
    release: "stable"
    matchExpressions:
    - {key: environment, operator: In, values: [dev]}

    configMap 一个特殊的数据卷,用来管理你的pod

    命令行创建一个configMap
    [root@master song]# kubectl create configmap nginx-config --from-literal=nginx_port=80 --from-literal=server_name=www.slele.com
    configmap/nginx-config created
    [root@master song]# kubectl get  configmaps -o yaml
    apiVersion: v1
    items:
    - apiVersion: v1
      data:
        nginx_port: "80"
        server_name: www.slele.com
      kind: ConfigMap
      metadata:
        creationTimestamp: "2019-03-09T05:12:39Z"
        name: nginx-config
        namespace: default
        resourceVersion: "2275161"
        selfLink: /api/v1/namespaces/default/configmaps/nginx-config
        uid: f5832bc1-4229-11e9-bc53-52540062b2ca
    kind: List
    metadata:
      resourceVersion: ""
      selfLink: ""

    [root@master song]# kubectl describe configmaps nginx-config
    Name: nginx-config
    Namespace: default
    Labels: <none>
    Annotations: <none>

    
    

    Data
    ====
    nginx_port:
    ----
    80
    server_name:
    ----
    www.slele.com
    Events: <none>

    将文件整体作为一个键值创建一个configmap

    [root@master song]# kubectl create configmap nginx-file --from-file=/etc/nginx/nginx.conf
    configmap/nginx-file created
    [root@master song]# kubectl describe configmaps nginx-file 
    Name:         nginx-file
    Namespace:    default
    Labels:       <none>
    Annotations:  <none>
    
    Data
    ====
    nginx.conf:
    ----
    # For more information on configuration, see:
    #   * Official English Documentation: http://nginx.org/en/docs/
    #   * Official Russian Documentation: http://nginx.org/ru/docs/
    
    user nginx;
    worker_processes auto;
    error_log /var/log/nginx/error.log;
    pid /run/nginx.pid;
    
    # Load dynamic modules. See /usr/share/nginx/README.dynamic.
    include /usr/share/nginx/modules/*.conf;
    
    events {
        worker_connections 1024;
    }
    
    http {
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
    
        access_log  /var/log/nginx/access.log  main;
    
        sendfile            on;
        tcp_nopush          on;
        tcp_nodelay         on;
        keepalive_timeout   65;
        types_hash_max_size 2048;
    
        include             /etc/nginx/mime.types;
        default_type        application/octet-stream;
    
        # Load modular configuration files from the /etc/nginx/conf.d directory.
        # See http://nginx.org/en/docs/ngx_core_module.html#include
        # for more information.
        include /etc/nginx/conf.d/*.conf;
    
        server {
            listen       80 default_server;
            listen       [::]:80 default_server;
            server_name  _;
            root         /usr/share/nginx/html;
    
            # Load configuration files for the default server block.
            include /etc/nginx/default.d/*.conf;
    
            location / {
            }
    
            error_page 404 /404.html;
                location = /40x.html {
            }
    
            error_page 500 502 503 504 /50x.html;
                location = /50x.html {
            }
        }
    
    # Settings for a TLS enabled server.
    #
    #    server {
    #        listen       443 ssl http2 default_server;
    #        listen       [::]:443 ssl http2 default_server;
    #        server_name  _;
    #        root         /usr/share/nginx/html;
    #
    #        ssl_certificate "/etc/pki/nginx/server.crt";
    #        ssl_certificate_key "/etc/pki/nginx/private/server.key";
    #        ssl_session_cache shared:SSL:1m;
    #        ssl_session_timeout  10m;
    #        ssl_ciphers HIGH:!aNULL:!MD5;
    #        ssl_prefer_server_ciphers on;
    #
    #        # Load configuration files for the default server block.
    #        include /etc/nginx/default.d/*.conf;
    #
    #        location / {
    #        }
    #
    #        error_page 404 /404.html;
    #            location = /40x.html {
    #        }
    #
    #        error_page 500 502 503 504 /50x.html;
    #            location = /50x.html {
    #        }
    #    }
    
    }
    
    
    Events:  <none>
  • 相关阅读:
    还在纠结注册.com域名还是.cn域名?
    网站域名被墙的检测查询和解决办法
    阿里云服务器无法远程其他的mysql服务器
    如何维护一个产品
    使用bootstrap+asp.net mvc4+IBatis.Net实现的小程序
    bootstrap IE兼容
    mongodb命令使用
    聊天工具实现winform端实现
    二级域名设置
    org
  • 原文地址:https://www.cnblogs.com/leleyao/p/10472172.html
Copyright © 2020-2023  润新知