This project demonstrates the usage of the official Kubernetes Go client (client-go) to interact with a Kubernetes cluster. It includes examples of:
- Connecting to a Kubernetes cluster using kubeconfig
- Listing pods across all namespaces
- Demonstrating error handling when getting pod information
- Go 1.16 or higher
- Access to a Kubernetes cluster
- Kubeconfig file configured with cluster access
The project uses the following main dependencies:
- k8s.io/client-go
- k8s.io/apimachinery
- Clone the repository:
git clone <repository-url>
cd k8s-crud-clientgo
- Install dependencies:
go mod tidy
- Run the application:
go run main.go
By default, the application will:
- Use your default kubeconfig file (~/.kube/config)
- List all pods in the cluster every 10 seconds
- Attempt to find a pod named "example-xxxxx" in the default namespace
You can specify a custom kubeconfig file location using the -kubeconfig
flag:
go run main.go -kubeconfig=/path/to/your/kubeconfig
- Cluster Connection: Establishes connection to a Kubernetes cluster using local kubeconfig
- Pod Listing: Periodically lists all pods in the cluster
- Error Handling: Demonstrates proper error handling for Kubernetes API operations
[Add your license information here]