modulepackage
2.0.1+incompatible
Repository: https://github.com/kubesys/client-go.git
Documentation: pkg.go.dev
# README
client-go
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 |
Comparison
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 |
Architecture
Installation
git clone --recursive https://github.com/kubesys/client-go
Maven users
Usage
Creating a client
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, err := kubesys.NewKubernetesClientWithDefaultKubeConfig()
if err == nil {
fmt.Println("Failed to get kubeconfig.")
return
}
client.Init()
simple-example
Assume you have a json:
{
"apiVersion": "v1",
"kind": "Pod",
"metadata": {
"name": "busybox",
"namespace": "default",
"labels": {
"test": "test"
}
}
}
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")
get-all-kinds
fmt.Println(client.GetKinds());
for developer
go mod init client-go
go mod tidy
RoadMap
- 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
# Packages
No description provided by the author
# Structs
No description provided by the author