收集整理一些可能较常用的api,结合kubernetes的自动化系统 以及 监控可能会用到。
注:涉及到POST方法中的json为发送的数据体。
get node
curl -i -k -H 'Authorization: Bearer lalalalalllaSDDDSASDASF=' -X GET https://10.10.5.103:6443/api/v1beta3/nodes
get namespace
curl -i -k -H 'Authorization: Bearer lalalalalllaSDDDSASDASF=' -X GET https://10.10.5.103:6443/api/v1beta3/namespaces
create namespace
curl -i -k -X POST https://10.10.5.103:6443/api/v1beta3/namespaces -H 'Authorization: Bearer lalalalalllaSDDDSASDASF=' -d "$(cat namespace-production.json)"
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"labels": {
"name": "production"
},
"name": "production"
}
}
create a pod
curl -i -k -X POST https://10.10.5.103:6443/api/v1beta3/namespaces/development/pods -H 'Authorization: Bearer lalalalalllaSDDDSASDASF=' -d "$(cat pod-8xxxxxxcom.json)
{
"kind": "Pod",
"apiVersion": "v1beta3",
"metadata": {
"name": "8xxxxxx",
"labels": {
"name": "8xxxxxx"
}
},
"spec":{
"volumes":[
{
"name":"log-vol",
"hostPath":{
"path":"/home/work/data/8_xxxxxx_com"
}
},
{
"name":"localtime",
"hostPath":{
"path":"/etc/localtime"
}
}
],
"containers":[
{
"name":"8-xxxxxx-com",
"image":"docker-registry.xxxxxx.com:5000/xxxxxx/8_xxxxxx_com:20150612",
"ports":[
{
"name":"ssh-port",
"containerPort":22,
"protocol":"TCP"
},
{
"name":"http-port",
"containerPort":8008,
"protocol":"TCP"
}
],
"volumeMounts":[
{
"mountPath":"/home/work/var/nfs",
"readOnly":false,
"name":"log-vol"
},
{
"mountPath":"/etc/localtime",
"readOnly":true,
"name":"localtime"
}
],
"imagePullPolicy": "Always"
}
]
}
}
get a pod:
curl -i -k -H 'Authorization: Bearer lalalalalllaSDDDSASDASF=' -X GET https://10.10.5.103:6443/api/v1beta3/pods
curl http://10.10.5.103:7080/api/v1beta3/namespaces/development/pods?labelSelector=name%3D8.xxxxxx.com
delete a pod:
curl -X DELETE http://10.10.5.103:18080/api/v1beta3/namespaces/development/pods/8xxxxxx
create a replication controller:
curl -i -k -X POST https://10.10.5.103:6443/api/v1beta3/namespaces/development/replicationcontrollers -H 'Authorization: Bearer lalalalalllaSDDDSASDASF=' -d "$(cat rc-8_xxxxxx_com.json)"
{
"kind":"ReplicationController",
"apiVersion":"v1beta3",
"id":"8.xxxxxx.com",
"metadata":{
"name":"8.xxxxxx.com",
"labels":{
"name":"8.xxxxxx.com"
}
},
"spec":{
"replicas":3,
"selector":{
"name":"8.xxxxxx.com"
},
"template":{
"metadata":{
"labels":{
"name":"8.xxxxxx.com"
}
},
"spec":{
"volumes":[
{
"name":"log-vol",
"hostPath":{
"path":"/home/work/data/8_xxxxxx_com"
}
},
{
"name":"localtime",
"hostPath":{
"path":"/etc/localtime"
}
}
],
"containers":[
{
"name":"8-xxxxxx-com",
"image":"docker-registry.xxxxxx.com:5000/xxxxxx/8_xxxxxx_com:20150612",
"ports":[
{
"name":"ssh-port",
"containerPort":22,
"protocol":"TCP"
},
{
"name":"http-port",
"containerPort":8008,
"protocol":"TCP"
}
],
"volumeMounts":[
{
"mountPath":"/home/work/var/nfs",
"readOnly":false,
"name":"log-vol"
},
{
"mountPath":"/etc/localtime",
"readOnly":true,
"name":"localtime"
}
],
"imagePullPolicy": "Always"
}
]
}
}
}
}
get a replication controller:
curl -i -k -H 'Authorization: Bearer lalalalalllaSDDDSASDASF=' -X GET https://10.10.5.103:6443/api/v1beta3/namespaces/development/replicationcontrollers
curl -i -k -H 'Authorization: Bearer lalalalalllaSDDDSASDASF=' -X GET https://10.10.5.103:6443/api/v1beta3/namespaces/development/replicationcontrollers/8.xxxxxx.com
delete a replication controller
curl -i -k -H 'Authorization: Bearer lalalalalllaSDDDSASDASF=' -X DELETE https://10.10.5.103:6443/api/v1beta3/namespaces/development/replicationcontrollers/8.xxxxxx.com
注意:删除replicationcontroller,对应的pod并不会级联删除,需要在手动调用pod delete删除对应的pod(略不爽~)
create a service
curl -i -k -X POST https://10.10.5.103:6443/api/v1beta3/namespaces/development/services -H 'Authorization: Bearer lalalalalllaSDDDSASDASF=' -d "$(cat svc-8xxxxxx.jso)"
{
"kind":"Service",
"apiVersion":"v1beta3",
"metadata":{
"name":"prometheus",
"labels":{
"name":"prometheus"
}
},
"spec":{
"ports": [
{
"port":8018,
"targetPort":8008,
"nodePort": 30061,
"protocol":"TCP"
}],
"type":"NodePort",
"selector":{
"name":"8.xxxxxx.com"
}
}
}
get a service
curl -i -k -H 'Authorization: Bearer lalalalalllaSDDDSASDASF=' -X GET https://10.10.5.103:6443/api/v1beta3/namespaces/development/services
curl -i -k -H 'Authorization: Bearer lalalalalllaSDDDSASDASF=' -X GET https://10.10.5.103:6443/api/v1beta3/namespaces/development/services/prometheus
delete a service
curl -i -k -H 'Authorization: Bearer lalalalalllaSDDDSASDASF=' -X DELETE https://10.10.5.103:6443/api/v1beta3/namespaces/development/services/prometheus
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。