Skip to content

Latest commit

 

History

History
59 lines (42 loc) · 1.42 KB

README.md

File metadata and controls

59 lines (42 loc) · 1.42 KB

Kubernetes Client-Go Example

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

Prerequisites

  • Go 1.16 or higher
  • Access to a Kubernetes cluster
  • Kubeconfig file configured with cluster access

Dependencies

The project uses the following main dependencies:

  • k8s.io/client-go
  • k8s.io/apimachinery

Building and Running

  1. Clone the repository:
git clone <repository-url>
cd k8s-crud-clientgo
  1. Install dependencies:
go mod tidy
  1. 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

Configuration

You can specify a custom kubeconfig file location using the -kubeconfig flag:

go run main.go -kubeconfig=/path/to/your/kubeconfig

Features

  1. Cluster Connection: Establishes connection to a Kubernetes cluster using local kubeconfig
  2. Pod Listing: Periodically lists all pods in the cluster
  3. Error Handling: Demonstrates proper error handling for Kubernetes API operations

License

[Add your license information here]