Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use kubernetes go-client on amazon eks service?

I've been looking for documentation for a long time and still couldn't find any clear connection procedure. I came up with this code sample :

package aws

import (
    "fmt"
    "net/http"

    "github.com/aws/aws-sdk-go/aws/session"
    "github.com/aws/aws-sdk-go/service/eks"
    "github.com/joho/godotenv"
)
func Connect() {
    godotenv.Load(".env")
    session := session.Must(session.NewSession())
    svc := eks.New(session)
    clusters, err := svc.ListClusters(&eks.ListClustersInput{})
    if err != nil {
        fmt.Println(err.Error())
    }
    fmt.Println(clusters)
}

i mean, this still returns a 403 forbidden error because of env variable mess, but the code is valid i guess. My question is, having this connection established : how to convert this svc variable into the *kubernetes.Clientset one from the go driver ?

like image 517
raphael.oester Avatar asked Dec 05 '25 13:12

raphael.oester


1 Answers

Have you had a look at the client-go example on how to authenticate in-cluster?

Code that authenticate to the Kubernetes API typically start like this:

    // creates the in-cluster config
    config, err := rest.InClusterConfig()
    if err != nil {
        panic(err.Error())
    }
    // creates the clientset
    clientset, err := kubernetes.NewForConfig(config)
    if err != nil {
        panic(err.Error())
    }
like image 97
Jonas Avatar answered Dec 08 '25 08:12

Jonas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!