Skip to content

ylighgh/K8SManager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

K8S Standard Resource Manager

A simple tool for managing Kubernetes resources, including operations like Get and Delete.

Installation

go get https://github.com/ylighgh/K8SManager.git

Usage

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()
}

Features

  • 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.

About

K8S 标准资源管理

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages