A package of useful functions for managing k8 cluster and helm charts
- when you want to install delete k8 manifest files
- get information on services and deployments ect
- deploy / delete /upgrade helm charts
- Add helm repo
- go 1.8 https://go.dev/doc/install to run and install go_k8_helm
This will take you through the steps to install and get go_k8_helm up and running.
1. Install
go get github.com/Mrpye/go_k8_helm
2. Add to your project
import "github.com/Mrpye/go_k8_helm"
1. Get workspace items pods deployments ...
package main
import "github.com/Mrpye/go_k8_helm"
func main() {
//*****************************************************************************
// Create the k8 connection
//you can pass in the kube config file path or leave black for default location
//*****************************************************************************
k8, err := go_k8_helm.CreateK8KubeConfig("minikube", "")
// ********************************
//Can also use the token connection
// ********************************
//k8, err := go_k8_helm.CreateK8Token("localhost","auth",true)
if err != nil {
panic(err)
}
//****************************
//get items from the workspace
//****************************
result, err := k8.GetServiceIP("default", "my_service")
if err != nil {
panic(err)
}
for _, s := range result {
println(s.ServiceName, s.IP, s.Port, s.ServiceType)
}
}
2. Get service IP
package main
import "github.com/Mrpye/go_k8_helm"
func main() {
//*****************************************************************************
// Create the k8 connection
//you can pass in the kube config file path or leave black for default location
//*****************************************************************************
k8, err := go_k8_helm.CreateK8KubeConfig("minikube", "")
// ********************************
//Can also use the token connection
// ********************************
//k8, err := go_k8_helm.CreateK8Token("localhost","auth",true)
if err != nil {
panic(err)
}
//****************************
//get items from the workspace
//****************************
result, err := k8.GetServiceIP("default", "my_service")
if err != nil {
panic(err)
}
for _, s := range result {
println(s.ServiceName, s.IP, s.Port, s.ServiceType)
}
}
3. Add helm repo and install/upgrade uninstall helm chart
package main
import "github.com/Mrpye/go_k8_helm"
func main() {
//*****************************************************************************
// Create the k8 connection
//you can pass in the kube config file path or leave black for default location
//*****************************************************************************
k8, err := go_k8_helm.CreateK8KubeConfig("minikube", "")
// ********************************
//Can also use the token connection
// ********************************
//k8, err := go_k8_helm.CreateK8Token("localhost","auth",true)
if err != nil {
panic(err)
}
//**********
//Add a repo
//**********
err = k8.RepoAdd("my_repo", "https://kubernetes-charts.storage.googleapis.com", "user", "password")
if err != nil {
panic(err)
}
//***************
//Update the repo
//***************
err = k8.RepoUpdate()
if err != nil {
panic(err)
}
//***************
//Deploy a chart
//***************
err = k8.DeployHelmChart("my_repo/char", "release_name", "default", map[string]interface{}{"key": "value"})
if err != nil {
panic(err)
}
//***************
//Upgrade a chart
//***************
err = k8.UpgradeHelmChart("my_repo/char", "release_name", "default", map[string]interface{}{"key": "value"})
if err != nil {
panic(err)
}
//***************
//Uninstall a chart
//***************
err = k8.UninstallHelmChart("my_repo/char", "release_name")
if err != nil {
panic(err)
}
}
- Write tests
go_k8_helm is Apache 2.0 licensed.
- Update documents
- Update functions Document
- Added Delete actions for pods, ns, deployments, service
- Added examples
- Update documents
- Document functions
- Added Delete actions for DemonSet, PV, PVC
- changed way DeleteNS works
- Fix a dependance that should not be getting used
- updated the reference for golib to v0.2.2