kubernetes@in-cluster : in-cluster name kubernetes-admin@kubernetes : kubeconfig default context name
| URL Pattern | Method | 설명 |
|---|---|---|
| /api/clusters | GET | k8s cluster context 리스트 조회 |
| /api/clusters/:cluster/topology | GET | 토플로지 그래프 조회 |
| /api/clusters/:cluster/dashboard | GET | Dashboard 데이터 조회 |
- Examples
$ curl -X GET http://localhost:3001/api/contexts
$ curl -X GET http://localhost:3001/api/clusters/kubernetes@in-cluster/graph/topology
$ curl -X GET http://localhost:3001/api/clusters/kubernetes@in-cluster/dashboard
멀티 클러스터를 지원하는 Kubernetes API Proxy API
- Kubernetes API Concepts
- OepnAPI spec.
- Kubernetes API 에서 제공하는 resource 와 resource의 api-group은
kubectl api-resources -o wide으로 resource와 apiGroup 조회 가능
$ kubectl api-resources -o wide
# CRD 경우
$ kubectl get crd
$ kubectl get crd virtualservices.networking.istio.io -o jsonpath="{.spec.group}"
- URL Patter은 다음과 같이 URL Prefix :
/raw와 kubernetes-api URL로 구성 - kubernetes-api 는 각 resource 의
metadata.selfLink참조 가능
/raw/<Kubernetes-api URL>
- 아래 설명에서 사용하는 변수는 다음과 같습니다.
:cluster: Kubeconfig context name:version: Resource spec. version:resource: Resource name:apiGroups: Resource groups
Create a resource
| URL Pattern | Method | 설명 |
|---|---|---|
| /raw/clusters/:cluster | POST | Applay |
- Example
$ curl -X POST -H "Content-Type: application/json" http://localhost:3001/raw/clusters/kubernetes@in-cluster -d @- <<EOF
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"name": "test-namespace"
}
}
EOF
Update a resource
| URL Pattern | Method | 설명 | 비고 |
|---|---|---|---|
| /raw/clusters/:cluster | PATCH | Update |
-
Reuqest Header
Content-Type으로 patch 방식 선택 (- patch 방식에 대한 이해 - Update API Objects in Place Using kubectl patch
- JSON Merge Patch (RFC 7396) :
Content-Type : application/merge-patch+json - JSON Patch (RFC 6902) :
Content-Type : application/json-patch+json - Strategic merge patch :
Content-Type : application/strategic-merge-patch+json
-
JSON merge patch example
$ curl -X PATCH -H "Content-Type: application/merge-patch+json" http://localhost:3001/raw/clusters/kubernetes@in-cluster/api/v1/namespaces/default/pods/busybox -d @- <<EOF
{
"metadata": {
"labels": {
"app": "busybox-merge"
}
}
}
EOF
$ kubectl get po busybox -n default -o jsonpath="{.metadata.labels}"
- JSON patch example
$ curl -X PATCH -H "Content-Type: application/json-patch+json" http://localhost:3001/raw/clusters/kubernetes@in-cluster/api/v1/namespaces/default/pods/busybox -d @- <<EOF
[
{
"op": "replace",
"path": "/metadata/labels/app",
"value":"busybox-json"
}
]
EOF
$ kubectl get po busybox -n default -o jsonpath="{.metadata.labels}"
- Resources는 다음과 같이 4가지로 분류 가능
| No. | Core | Namespaced | Resources |
|---|---|---|---|
| 1 | O | O | Pod, Service, PersistentVolumeClaim, ... |
| 2 | O | X | Namespace, PersistentVolume, ... |
| 3 | X | O | Deployment, DaemonSet, PodMetrics, Role, RoleBinding, ... |
| 4 | X | X | NodeMetrics, ClusterRole, ClusterRoleBinding, ... |
| URL | Method | 설명 |
|---|---|---|
| /raw/clusters/:cluster/api/:version/:resource | GET | non-namespaced 리소스 목록 조회 |
| /raw/clusters/:cluster/api/:version/:resource:/:name | GET | non-namespaced 리소스 조회 |
| /raw/clusters/:cluster/api/:version/:resource:/:name | DELETE | non-namespaced 리소스 삭제 |
| /raw/clusters/:cluster/api/:version/:resource:/:name | PATCH | non-namespaced 리소스 수정 |
| /raw/clusters/:cluster/api/:version/namespaces/:resource: | GET | namespaced 리소스 목록조회 |
| /raw/clusters/:cluster/api/:version/namespaces/:namespace/:resource/:name | GET | namespaced 리소스 조회 |
| /raw/clusters/:cluster/api/:version/namespaces/:namespace/:resource/:name | DELETE | N\namespaced 리소스 삭제 |
| /raw/clusters/:cluster/api/:version/namespaces/:namespace/:resource/:name | PATCH | N\namespaced 리소스 수정 |
| URL | Method | 설명 |
|---|---|---|
| /raw/clusters/:cluster/apis/:apiGroup/:version/:resource | GET | non-namespaced 리소스 목록 조회 |
| /raw/clusters/:cluster/apis/:apiGroup/:version/:resource:/:name | GET | non-namespaced 리소스 조회 |
| /raw/clusters/:cluster/apis/:apiGroup/:version/:resource:/:name | DELETE | non-namespaced 리소스 삭제 |
| /raw/clusters/:cluster/apis/:apiGroup/:version/:resource:/:name | PATCH | non-namespaced 리소스 수정 |
| /raw/clusters/:cluster/apis/:apiGroup/:version/namespaces/:resource: | GET | namespaced 리소스 목록조회 |
| /raw/clusters/:cluster/apis/:apiGroup/:version/namespaces/:namespace/:resource/:name | GET | namespaced 리소스 조회 |
| /raw/clusters/:cluster/apis/:apiGroup/:version/namespaces/:namespace/:resource/:name | DELETE | namespaced 리소스 삭제 |
| /raw/clusters/:cluster/apis/:apiGroup/:version/namespaces/:namespace/:resource/:name | PATCH | namespaced 리소스 수정 |
# Create
$ curl -X POST -H "Content-Type: application/json" http://localhost:3001/raw/clusters/kubernetes@in-cluster -d @- <<EOF
{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": {
"name": "test-namespace"
}
}
EOF
# Get
$ curl -X GET http://localhost:3001/raw/clusters/kubernetes@in-cluster/api/v1/namespaces/test-namespace
# Update
$ curl -X PATCH -H "Content-Type: application/merge-patch+json" http://localhost:3001/raw/clusters/kubernetes@in-cluster/api/v1/namespaces/test-namespace -d @- <<EOF
{
"metadata": {
"labels": {
"istio-injection": "disabled"
}
}
}
EOF
# verify
$ kubectl get ns/test-namespace -o jsonpath={.metadata.labels.istio-injection}
# Delete
$ curl -X DELETE http://localhost:3001/raw/clusters/kubernetes@in-cluster/api/v1/namespaces/test-namespace
# List
$ curl -X GET http://localhost:3001/raw/clusters/kubernetes@in-cluster/api/v1/namespaces
| URL Pattern | Method | 설명 |
|---|---|---|
| /api/v1/clusters/:cluster | GET | summary metrics 조회 |
| /api/v1/clusters/:cluster/nodes/:node | GET | Node metrics 조회 |
| /api/v1/clusters/:cluster/namespaces/:namespaces/pods/:pod | GET | Pod metrics 조회 |
-
변수
:cluster: Kubeconfig context name:node: Node name:metrics:cpuormemory:pod: Pod name
-
Examples
$ curl -X GET http://localhost:8000/api/v1/clusters/kubernetes@in-cluster
$ curl -X GET http://localhost:8000/api/v1/clusters/kubernetes@in-cluster/nodes/vm-live-01
$ curl -X GET http://localhost:8000/api/v1/clusters/kubernetes@in-cluster/namespaces/default/pods/busybox
-
아래 설명에서 사용하는 변수는 다음과 같습니다.
clusters: Kubeconfig context namenamespaces: Resource namespacepods: Pod namecontainers: Container nametermtype: terminal type(cluster/pod/container)
-
prefix : /api/terminal/clusters/{CLUSTER}
| URL Pattern | Method | 설명 |
|---|---|---|
| termtype/{TERMTYPE} | GET | Web terminal 접속토큰 요청(kubectl) |
| namespaces/{NAMESPACE}/pods/{POD}/termtype/{TERMTYPE} | GET | Web terminal 접속토큰 요청(pod) |
| namespaces/{NAMESPACE}/pods/{POD}/containers/{CONTAINER}/termtype/{TERMTYPE} | GET | Web terminal 접속토큰 요청(container) |
- anothers
| URL Pattern | Method | 설명 |
|---|---|---|
| /api/terminal/ws | GET | Web terminal websocket 접속요청 |
| /api/v1/config | PATCH | kubeconfig refresh event from backend |