자바스크립트를 활성화 해주세요

d092 코드로 kubernetes api 다루기

 ·  ☕ 1 min read

kubectl

d092_kubernetes_api_code.png

감 잡히시죠? powershell 사용합니다.

1
2
3
$json = [string](kubectl get service -o json)
$pods = ConvertFrom-Json $json
$pods.apiVersion

kubernetes-client

다음은 공식 k8s python client입니다.

https://github.com/kubernetes-client/python

dataspell 사용은 이렇게 합니다.

d092_kubernetes_api_code_with_dataspell.png

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
from kubernetes import client, config

# Configs can be set in Configuration class directly or using helper utility
config.load_kube_config()

v1 = client.CoreV1Api()
print("Listing pods with their IPs:")
ret = v1.list_pod_for_all_namespaces(watch=False)
for i in ret.items:
        print("%s\t%s\t%s" % (i.status.pod_ip, i.metadata.namespace, i.metadata.name))

이걸로 뭘 할 수 있는 지는 상상의 나래 저편에 있겠죠.

감상

  • 그런데, k8s라면 go언어로 다루어줘야 하는 거 아닌가요?
공유하기

tkim
글쓴이
tkim
Software Engineer