kubernetes 实用 api list

https://192.168.20.128:6443/api/v1/pods


原文来自https://segmentfault.com/a/1190000002937665



收集整理一些可能较常用的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

转载于:https://www.cnblogs.com/lykops/p/8263122.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值