
# 使用kubectl自动创建对象存储
#### 操作场景
动态使用OBS可以自动创建并挂载所期望的OBS对象存储，目前支持标准、低频两种类型的桶，分别对应obs-standard、obs-standard-ia。
#### 约束与限制
如下配置示例适用于Kubernetes 1.13及以下版本的集群。
#### 操作步骤
1. 请参见[通过kubectl连接集群](https://support.huaweicloud.com/usermanual-cce/cce_10_0107.html)，使用kubectl连接集群。
2. 执行如下命令，配置名为"pvc-obs-auto-example.yaml"的创建PVC的yaml文件。 
   **touch pvc-obs-auto-example.yaml**
   **vi pvc-obs-auto-example.yaml**
   **yaml** **示例如下：**
   ```
   apiVersion: v1 
   kind: PersistentVolumeClaim 
   metadata: 
     annotations: 
       volume.beta.kubernetes.io/storage-class: obs-standard  # 对象存储桶类型，当前支持标准（obs-standard）和低频（obs-standard-ia）
     name: pvc-obs-auto-example  # PVC名称
     namespace: default 
   spec: 
     accessModes: 
     - ReadWriteMany 
     resources: 
       requests: 
         storage: 1Gi   # 存储容量，单位为Gi，对OBS桶来说，此处仅为校验需要（不能为空和0），设置的大小不起作用，此处设定为固定值1Gi
   ```
   表1关键参数说明 
   | 参数                                      | 描述                                                         |
   |:---|:---|
   | volume.beta.kubernetes.io/storage-class | 桶类型，当前支持标准（obs-standard）和低频（obs-standard-ia）两种桶。           |
   | name                                    | 创建的PVC名称。                                                  |
   | accessModes                             | 只支持ReadWriteMany，不支持ReadWriteOnce。                         |
   | storage                                 | 存储容量，单位为Gi，对OBS桶来说，此处仅为校验需要（不能为空和0），设置的大小不起作用，此处设定为固定值1Gi。 |
      
   
   
3. 执行如下命令创建PVC。 
   kubectl create -f pvc-obs-auto-example.yaml
   命令执行完成后会在集群所在VPC内创建一个对象存储桶，您可以在"存储管理 \> 对象存储卷"中单击桶名称查看该桶，也可以在OBS的控制台查看该桶。
   
   
 
