Yandex.Cloud
  • Services
  • Why Yandex.Cloud
  • Pricing
  • Documentation
  • Contact us
Get started
Yandex Managed Service for Kubernetes
  • Getting started
  • Step-by-step instructions
    • All instructions
    • Connecting to a node over SSH
    • Creating a configuration file
    • Configuring a Kubernetes cluster network
      • Granting access to an app running in a Kubernetes cluster
      • Using Kubernetes cluster network policies
    • Encrypting secrets
    • Using persistent volumes
      • Dynamically preparing volumes
      • Statically preparing volumes
      • Managing storage classes
      • Expanding a volume
      • Mounting a volume in Block mode
    • Managing a Kubernetes cluster
      • Adding Kubernetes cluster credentials to the kubectl configuration file
      • Getting information about a Kubernetes cluster
      • Creating a Kubernetes cluster
      • Editing a Kubernetes cluster
      • Deleting a Kubernetes cluster
    • Managing a node group
      • Getting information about a node group
      • Creating a node group
      • Editing a node group
      • Deleting a node group
  • Solutions
    • Integration with Container Registry
    • Running workloads with GPUs
    • Making backups to Object Storage
  • Concepts
    • Relationship between service resources
    • Release channels and updates
    • Using Kubernetes API objects
      • Volume
      • Service
    • Node group
      • Autoscaling node groups
      • Evicting pods from a node
      • Dynamic resource allocation for a node
      • Node groups with GPUs
    • Kubernetes cluster network policies
    • Quotas and limits
  • Access management
  • Pricing policy
  • API reference
    • Authentication in the API
    • gRPC
      • Overview
      • ClusterService
      • NodeGroupService
      • VersionService
      • OperationService
    • REST
      • Overview
      • Cluster
        • Overview
        • create
        • delete
        • get
        • list
        • listNodeGroups
        • listNodes
        • listOperations
        • start
        • stop
        • update
      • NodeGroup
        • Overview
        • create
        • delete
        • get
        • list
        • listNodes
        • listOperations
        • update
      • Version
        • Overview
        • list
  • Questions and answers
  1. Step-by-step instructions
  2. Using persistent volumes
  3. Statically preparing volumes

Static volume provisioning

  • Before getting started
  • Create a PersistentVolume
  • Create a PersistentVolumeClaim
  • Create a pod with a statically provisioned volume

Create a pod with a statically provisioned volume:

  1. Create a PersistentVolume.
  2. Create a PersistentVolumeClaim.
  3. Create a pod.

Before getting started

Look up the unique ID of the disk to be used to create the PersistentVolume, or create a new disk:

  1. If you don't have a disk yet, create one.

  2. Look up the unique disk ID:

    $ yc compute disk list
    +----------------------+------+--------------+---------------+--------+----------------------+-------------+
    |          ID          | NAME |     SIZE     |     ZONE      | STATUS |     INSTANCE IDS     | DESCRIPTION |
    +----------------------+------+--------------+---------------+--------+----------------------+-------------+
    | ef3ouo4sgl86740ridn6 | k8s  |   4294967296 | ru-central1-c | READY  |                      |             |
    | ef3qh55ckuu7md2kqhbt |      | 103079215104 | ru-central1-c | READY  | ef3sin41eksav1kn4gct |             |
    | epd9vda1h0knttpcuhfu |      |  10737418240 | ru-central1-b | READY  | epdegdecs9o14r13gbad |             |
    +----------------------+------+--------------+---------------+--------+----------------------+-------------+
    

Create a PersistentVolume

  1. Save the PersistentVolume creation specification to a YAML file named test-pv.yaml.

    To learn more about the specification, see the Kubernetes documentation.

    When setting the capacity: storage parameter, make sure you specify the exact size of the disk. CSI doesn't validate the disk size for statically provisioned volumes.

    To create a PersistentVolume from an existing cloud drive, enter its unique disk ID in the volumeHandle parameter.

    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: test-pv
    spec:
      capacity:
        storage: 4Gi 
      accessModes:
        - ReadWriteOnce 
      csi:
        driver: disk-csi-driver.mks.ycloud.io
        fsType: ext4
        volumeHandle: ef3ouo4sgl86740ridn6
    
  2. Run the command:

    $ kubectl create -f test-pv.yaml
    persistentvolume/test-pv created
    
  3. View information about the PersistentVolume created:

    $ kubectl describe persistentvolume test-pv
    Name:            test-pv
    Labels:          <none>
    Annotations:     <none>
    Finalizers:      [kubernetes.io/pv-protection]
    StorageClass:    yc-network-hdd
    Status:          Available
    ...
    

Create a PersistentVolumeClaim

  1. Save the PersistentVolumeClaim creation specification to a YAML file named test-claim.yaml.

    To learn more about the specification, see the Kubernetes documentation.

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: test-claim
    spec:
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 4Gi
      volumeName: test-pv
    
    1. Run the command:

      $ kubectl create -f test-claim.yaml
      persistentvolumeclaim/test-claim created
      
    2. View information about the PersistentVolumeClaim created:

      $ kubectl describe persistentvolumeclaim test-claim
      Name:          test-claim
      Namespace:     default
      StorageClass:  yc-network-hdd
      Status:        Bound
      Volume:        test-pv
      ...
      

Create a pod with a statically provisioned volume

  1. Save the following example to a YAML file named test-pod.yaml.

    apiVersion: v1
    kind: Pod
    metadata:
      name: test-pod
    spec:
      containers:
      - name: app
        image: ubuntu
        command: ["/bin/sh"]
        args: ["-c", "while true; do echo $(date -u) >> /data/out.txt; sleep 5; done"]
        volumeMounts:
        - name: persistent-storage
          mountPath: /data
      volumes:
      - name: persistent-storage
        persistentVolumeClaim:
          claimName:  test-claim
    

    To learn more about the specification, see the Kubernetes documentation.

  2. Run the command:

    $ kubectl create -f test-pod.yaml
    pod/test-pod created
    
  3. View information about the pod created:

    $ kubectl describe pod test-pod
    Name:         test-pod
    Namespace:    default
    Priority:     0
    Node:         cl1gqrct5oier258n08t-ypap/10.0.0.9
    Start Time:   Tue, 23 Jul 2019 18:34:57 +0300
    Labels:       <none>
    Annotations:  <none>
    Status:       Pending
    ...
    Events:
      Type    Reason     Age   From               Message
      ----    ------     ----  ----               -------
      Normal  Scheduled  3s    default-scheduler  Successfully assigned default/test-pod to cl1gqrct5oier258n08t-ypap
    

In the Compute Cloud management console under Disks, you will see the word Active next to the disk you're using.

In this article:
  • Before getting started
  • Create a PersistentVolume
  • Create a PersistentVolumeClaim
  • Create a pod with a statically provisioned volume
Language
Careers
Privacy policy
Terms of use
© 2021 Yandex.Cloud LLC