-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
zio remote cluster authentication and pod listing #248
Comments
Thank you for submitting this issue and welcome! |
Hi @MohammadForouhesh , ZIO module uses ZIO http, which lacks the TLS support required for connecting to kubernetes directly and the 403 error is because of this. There are a few different ways you can resolve this problem:
Hope this helps! Let me know if there are any problems or questions. |
Thanks @hnaderi, for your timely response. Since we will deploy it on the same cluster at the end of the day, and it will work with its service account, can you provide me with some insight on that? and also, can you please further elaborate on your 3rd solution? It would be highly appreciated if you provide me with a working code of your 2nd solution. |
If you want to access kubernetes API using service account credentials, the easiest approach would be number 1 or number 2, as the http4s client supports automatic detection of credentials from pod or kubeconfig or from environment variables, exactly like how For third solution, you need to run ZIOKubernetesClient.make("http://localhost:8001") See here for complete example. For second solution, I will send an example later today, or probably by tomorrow. |
Here's a working example using ZIO, ZIO interop, http4s; that gets a node list. /*
* Copyright 2021 Hossein Naderi
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//> using scala 3.3
//> using dep "io.circe::circe-generic:0.14.6"
//> using dep "dev.hnaderi::scala-k8s-http4s-ember:0.15.2"
//> using dep "dev.hnaderi::scala-k8s-circe:0.15.2"
//> using dep "org.http4s::http4s-circe:0.23.24"
//> using dep "dev.zio::zio:2.0.19"
//> using dep "dev.zio::zio-interop-cats:23.1.0.0"
package example
import cats.effect._
import cats.effect.std.Env
import zio._
import zio.Console._
import zio.interop.catz._
import dev.hnaderi.k8s.circe._
import dev.hnaderi.k8s.client._
import dev.hnaderi.k8s.client.http4s.EmberKubernetesClient
import io.circe.Json
import org.http4s.circe._
object App extends ZIOAppDefault {
given Env[Task] = new {
def get(name: String) = ZIO.succeed(sys.env.get(name))
def entries = ZIO.succeed(sys.env)
}
val buildClient = EmberKubernetesClient[Task].defaultConfig[Json]
def run = buildClient.use(APIs.nodes.list().send).flatMap(nl=> printLine(nl.toString()))
} You can run it directly using |
thanks a lot, it really helped |
Hi @hnaderi, documentation for listing pods (simplest example) in zio when we have a remote cluster is missing. the following code was the best I came up with.
and I encounter the following error:
any help will be highly appreciated.
The text was updated successfully, but these errors were encountered: