We expect to provide a go client:
- Flexibility. It can support all Kubernetes-based systems with minimized extra development, such as Openshift, istio, etc.
- Usability. Developers just need to learn to write json/yaml(kubernetes native style) from Kubernetes documentation.
- Integration. It can work with the other Kubernetes clients, such as official.
This project is based on the following softwares.
NAME | Website | LICENSE |
---|---|---|
gjson | https://github.com/tidwall/gjson | MIT |
match | https://github.com/tidwall/match | MIT |
pretty | https://github.com/tidwall/pretty | MIT |
official | cdk8s | this project | |
---|---|---|---|
Compatibility | for kubernetes-native kinds | for crd kinds | for both |
Support customized Kubernetes resources | a lot of development | a lot of development | zero-deployment |
Works with the other SDKs | complex | complex | simple |
- National Key Research and Development Program of China (2023YFB3308702)
git clone --recursive https://github.com/kubesys/client-go
There are two ways to create a client:
- By url and token:
client := new KubernetesClient(url, token);
client.Init()
Here, the token can be created and get by following commands:
- create token
kubectl create -f https://raw.githubusercontent.com/kubesys/client-go/master/account.yaml
- get token
kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep kubernetes-client | awk '{print $1}') | grep "token:" | awk -F":" '{print$2}' | sed 's/ //g'
- By kubeconfig:
client := kubesys.NewKubernetesClientWithDefaultKubeConfig()
client.Init()
Assume you have a json:
{
"apiVersion": "v1",
"kind": "Pod",
"metadata": {
"name": "busybox1",
"namespace": "default"
},
"spec": {
"containers": [
{
"command": [
"sleep",
"3600"
],
"image": "busybox",
"imagePullPolicy": "IfNotPresent",
"name": "busybox"
}
]
}
}
List resources:
client.ListResources("Pod")
Create a resource:
client.CreateResource(json);
Get a resource:
client.GetResource("Pod", "default", "busybox");
Delete a resource::
client.DeleteResource("Pod", "default", "busybox")
fmt.Println(client.GetKinds());
go mod init client-go
go mod tidy
- 2.0.x: product ready
- 2.0.0: using jsonparser
- 2.0.1: support kubeconfig
- 2.0.2: support yaml
- 2.0.3: support binding