A simple tool for managing Kubernetes resources, including operations like Get
and Delete
.
go get https://github.com/ylighgh/K8SManager.git
To use the K8SManager in your Go project, include the following import:
import (
"context"
"flag"
"fmt"
"path/filepath"
"time"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir"
k8sManager "github.com/ylighgh/K8SManager.git"
)
func main() {
var kubeconfig *string
if home := homedir.HomeDir(); home != "" {
kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")
} else {
kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")
}
flag.Parse()
// Use the current context in kubeconfig
config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
if err != nil {
panic(err.Error())
}
// Create the Kubernetes clientset
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
panic(err.Error())
}
// Initialize the K8S Manager
k8sManager.InitK8SManager(clientset)
manager := k8sManager.K8SManager
// DeploymentManager
deployManager := manager.DeploymentManager()
// xxxManager
xxxManager := manager.XxxManager()
}
- Resource Management: Easily manage Kubernetes resources like Deployments, Pods, Services, etc.
- Get & Delete: Perform GET, DELETE, and other operations on resources in a Kubernetes cluster.
- Easy Integration: Works seamlessly with your Go applications, providing simple and efficient resource management capabilities.