华为云云容器实例服务级联删除验证

华为云容器服务对外开放了原生的Kubernetes Api接口,对应的API的描述可参考
https://support.huaweicloud.com/cci_dld/index.htmlhttps://support.huaweicloud.com/api-cci/cci_02_0012.html
需要特别注意的是,在调用API进行Kubernetes资源删除的时候,原生API默认的操作是不进行级联删除的,即删除Deployment(对应华为云容器实例服务的无状态负载)的时候,默认是不是删除ReplicaSet和对应的POD的。需要通过propagationPolicy选项进行指定。可以参考社区的描述https://kubernetes.io/docs/concepts/workloads/controllers/garbage-collection/#foreground-cascading-deletion

下面以负载alex-testalex-test2为例描述一下级联删除和非级联删除的方法及结果。

获取token

token=`curl -i -H 'Accept:application/json' -H 'Content-Type:application/json;charset=utf8' -X POST -d @token.json  https://iam.cn-north-1.myhuaweicloud.com/v3/auth/tokens 2>/dev/null | grep "X-Subject-Token" | awk '{print $2}'`

其中token.json的内容为:

{
  "auth": {
    "identity": {
      "methods": [
        "password"
      ],
      "password": {
        "user": {
          "name": "alex_mahao",   //自己的用户名
          "password": "Huawei@123",  //自己的用户密码
          "domain": {
            "name": "alex_mahao"  // 账号名
          }
        }
      }
    },
    "scope": {
      "project": {
         "name": "cn-north-1"
      }
    }
  }
}

查询指定的无状态负载的信息

project_id=24a4509fd5ca41e3a18d24f8957c8704

deployment_name=alex-test

curl -k -X GET -H "X-Auth-Token:$token" -H "Content-Type:application/json" https://cci.cn-north-1.myhuaweicloud.com:443/apis/apps/v1beta1/namespaces/$project_id/deployments/$deployment_name

查询所有的pod信息

curl -k -X GET -H "X-Auth-Token:$token" -H "Content-Type:application/json" https://cci.cn-north-1.myhuaweicloud.com:443/api/v1/namespaces/$project_id/pods

非级联删除无状态负载

curl -k -XDELETE -H "X-Auth-Token:$token" -H "Content-Type:application/json" https://cci.cn-north-1.myhuaweicloud.com:443/apis/apps/v1beta1/namespaces/$project_id/deployments/$deployment_name

删除结果

级联删除

deployment_name=alex-test2

curl -k -XDELETE -d @backend.json -H "X-Auth-Token:$token" -H "Content-Type:application/json" https://cci.cn-north-1.myhuaweicloud.com:443/apis/apps/v1beta1/namespaces/$project_id/deployments/$deployment_name

​ backend.json

{
    "Kind": "DeleteOptions",
    "apiVersion": "v1",
    "propagationPolicy": "Background"
}
级联删除前
级联删除后

你可能感兴趣的:(华为云云容器实例服务级联删除验证)