gokubernetesamazon-eksclient-go

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 ?


Solution

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