云容器实例 CCI
云容器实例 CCI
- 最新动态
- 功能总览
- 产品介绍
- 计费说明
- 快速入门
- 用户指南
- 最佳实践
- 开发指南
-
API参考
- 使用前必读
- 如何调用API
- 快速入门
- API
-
Kubernetes API
- ConfigMap
- Pod
- StorageClass
- Service
- Deployment
- Ingress
- OpenAPIv2
- VolcanoJob
- Namespace
- ClusterRole
- Secret
- Endpoint
- ResourceQuota
- CronJob
-
API groups
- 查询APIVersions
- 查询所有v1版本的API
- 查询APIGroupList
- 查询APIGroup /apis/apps
- 查询所有apps/v1的API
- 查询APIGroup /apis/batch
- 查询APIGroup /apis/batch.volcano.sh
- 查询所有batch.volcano.sh/v1alpha1的API
- 查询所有batch/v1的API
- 查询所有batch/v1beta1的API
- 查询APIGroup /apis/crd.yangtse.cni
- 查询所有crd.yangtse.cni/v1的API
- 查询APIGroup /apis/extensions
- 查询所有extensions/v1beta1的API
- 查询APIGroup /apis/metrics.k8s.io
- 查询所有metrics.k8s.io/v1beta1的API
- 查询APIGroup /apis/networking.cci.io
- 查询所有networking.cci.io/v1beta1的API
- 查询APIGroup /apis/rbac.authorization.k8s.io
- 查询所有rbac.authorization.k8s.io/v1的API
- Event
- PersistentVolumeClaim
- RoleBinding
- StatefulSet
- Job
- ReplicaSet
- 数据结构
- 权限和授权项
- 附录
- 历史API
- 修订记录
- SDK参考
- 场景代码示例
- 常见问题
- 视频帮助
- 文档下载
- 通用参考
本文导读
展开导读
链接复制成功!
PATCH请求方法操作示例
本章节主要介绍PATCH请求方法中,“Merge Patch”与“Strategic Merge Patch”类型的操作示例。
操作示例
以创建Deployment资源对象为例。
请求示例
{ "apiVersion": "v1", "kind": "Deployment", "metadata": { "name": "nginx" }, "spec": { "replicas": 2, "selector": { "app": "nginx" }, "template": { "metadata": { "labels": { "app": "nginx" } }, "spec": { "containers": [ { "name": "redis", "image": "redis:latest", "ports": [ { "containerPort": 80 } ] } ] } } } }
响应示例
{ "kind": "ReplicationController", "apiVersion": "v1", "metadata": { "name": "frontend-controller", "namespace": "default", "selfLink": "/api/v1/namespaces/default/replicationcontrollers/nginx-controller", "uid": "549b2234-5d46-11e6-aeb9-286ed488fafe", "resourceVersion": "4110", "generation": 1, "creationTimestamp": "2016-08-08T08:58:52Z", "labels": { "app": "nginx" } }, "spec": { "replicas": 2, "selector": { "app": "nginx" }, "template": { "metadata": { "creationTimestamp": null, "labels": { "app": "nginx" } }, "spec": { "containers": [ { "name": "redis", "image": "redis:latest", "ports": [ { "containerPort": 80, "protocol": "TCP" } ], "resources": {}, "terminationMessagePath": "/dev/termination-log", "imagePullPolicy": "Always" } ], "restartPolicy": "Always", "dnsPolicy": "ClusterFirst", "securityContext": {} } } }, "status": { "replicas": 0 } }
- 如果使用“Merge Patch”类型操作,添加一个容器到指定Deployment的“template”参数中,则其中的整个容器列表将被新添加的容器所替换。
Merge Patch请求
{ "spec": { "template": { "spec": { "containers": [ { "name": "hello-world", "image": "busybox:latest" } ] } } } }
Merge Patch响应
{ "kind": "ReplicationController", "apiVersion": "v1", "metadata": { "name": "frontend-controller", "namespace": "default", "selfLink": "/api/v1/namespaces/default/replicationcontrollers/nginx-controller", "uid": "549b2234-5d46-11e6-aeb9-286ed488fafe", "resourceVersion": "4159", "generation": 2, "creationTimestamp": "2016-08-08T08:58:52Z", "labels": { "app": "nginx" } }, "spec": { "replicas": 2, "selector": { "app": "nginx" }, "template": { "metadata": { "creationTimestamp": null, "labels": { "app": "nginx" } }, "spec": { "containers": [ { "name": "hello-world", "image": "busybox:latest", "resources": {}, "terminationMessagePath": "/dev/termination-log", "imagePullPolicy": "Always" } ], "restartPolicy": "Always", "dnsPolicy": "ClusterFirst", "securityContext": {} } } }, "status": { "replicas": 2, "fullyLabeledReplicas": 2, "observedGeneration": 1 } }
其中“containers”参数列表被新添加的内容所替换。
- 而使用“Strategic Merge Patch”类型操作,是添加元数据到资源对象中,并通过这些新元数据来决定各个列表是否需要被合并。
Strategic Merge Patch请求
{ "spec": { "template": { "spec": { "containers": [ { "name": "hello-world", "image": "busybox:latest" } ] } } } }
Strategic Merge Patch响应
{ "kind": "ReplicationController", "apiVersion": "v1", "metadata": { "name": "frontend-controller", "namespace": "default", "selfLink": "/api/v1/namespaces/default/replicationcontrollers/nginx-controller", "uid": "f2e048bb-5d46-11e6-aeb9-286ed488fafe", "resourceVersion": "4250", "generation": 2, "creationTimestamp": "2016-08-08T09:03:18Z", "labels": { "app": "nginx" } }, "spec": { "replicas": 2, "selector": { "app": "nginx" }, "template": { "metadata": { "creationTimestamp": null, "labels": { "app": "nginx" } }, "spec": { "containers": [ { "name": "redis", "image": "redis:latest", "ports": [ { "containerPort": 80, "protocol": "TCP" } ], "resources": {}, "terminationMessagePath": "/dev/termination-log", "imagePullPolicy": "Always" }, { "name": "hello-world", "image": "busybox:latest", "resources": {}, "terminationMessagePath": "/dev/termination-log", "imagePullPolicy": "Always" } ], "restartPolicy": "Always", "dnsPolicy": "ClusterFirst", "securityContext": {} } } }, "status": { "replicas": 2, "fullyLabeledReplicas": 2, "observedGeneration": 1 } }
其中“containers”参数列表与新添加的内容合并,而不是替换,合并的依据为“name”域的值。
父主题: 附录