I'm trying to get the list of services from EKS using Spring boot and Kotlin. I was able to make it work with the following using fabric8:
@Configuration
class AwsConfig {
@Bean
fun kubernetesClient(): KubernetesClient {
return KubernetesClientBuilder()
.withConfig(
ConfigBuilder()
.withMasterUrl("master-url")
.withOauthToken(
"hard-coded-oauth-token"
)
.withTrustCerts()
.build(),
)
.build()
}
}
and then:
@Service
class EksService(val kubernetesClient: KubernetesClient) {
fun getServices() {
val services = kubernetesClient.services().list()
println(services)
}
}
I generated the "hard-coded-oauth-token" via cli command: aws eks get-token --cluster-name <cluster-name>
I'm trying to figure out how I can generate this oauth token progrematically, I couldn't find any documentation on that
I finally figured it out, with the help of this answer: https://stackoverflow.com/a/60204304
The code is in kotlin: