k8s 中文文档 k8s 中文文档
指南
kubernetes.io (opens new window)
指南
kubernetes.io (opens new window)
  • k8s 是什么
  • 互动教程

  • Minikube 介绍

  • 概念

  • Kubectl CLI

  • Kubectl 命令表

  • 安装设置

  • API 使用

  • 集群管理

  • TASKS

Skuber


Skuber is a Scala client library for Kubernetes. It provides a fully featured, high-level and strongly typed Scala API for managing Kubernetes cluster resources (such as Pods, Services, Deployments, ReplicaSets, Ingresses  etc.) via the Kubernetes REST API server.

Features


Comprehensive support for Kubernetes API model represented as Scala case classes
Support for core, extensions and other Kubernetes API groups
Full support for converting resources between the case class and standard JSON representations
Client API for creating, reading, updating, removing, listing and watching resources on a Kubernetes cluster
The API is asynchronous and strongly typed e.g. k8s getDeployment returns a value of type Future[Deployment]
Fluent API for creating and updating specifications of Kubernetes resources
Uses standard kubeconfig files for configuration - see the configuration guide for details

See the programming guide for more details.

Example


This example lists pods in kube-system namespace:

  1. ``` scala
  2. import skuber._
  3. import skuber.json.format._
  4. import akka.actor.ActorSystem
  5. import scala.util.{Success, Failure}

  6. implicit val system = ActorSystem()
  7. implicit val dispatcher = system.dispatcher

  8. val k8s = k8sInit
  9. val listPodsRequest = k8s.listInNamespace[PodList]("kube-system")
  10. listPodsRequest.onComplete {
  11.   case Success(pods) => pods.items.foreach { p => println(p.name) }
  12.   case Failure(e) => throw(e)
  13. }
  14. ```

See more elaborate example here.

Quick Start


Make sure prerequisites are met. There are couple of quick ways to get started with Skuber:

With Ammonite-REPL


Provides you with a configured client on startup. It is handy to use this for quick experiments.

using bash

  1. ``` shell
  2. $ amm -p ./Quickstart.sc
  3. ```

from inside ammonite-repl:

  1. ``` scala
  2. import $file.`Quickstart`, Quickstart._
  3. ```

Just handy shortcut to import skuber inside ammonite-repl:


  1. ``` scala
  2. import $ivy.`io.skuber::skuber:2.6.7`, skuber._, skuber.json.format._
  3. ```

Interactive with sbt


Clone this repository.

Tell Skuber to configure itself from the default Kubeconfig file ($HOME/.kube/config ):

  1. ``` shell
  2. export SKUBER_CONFIG=file
  3. ```

Read more about Skuber configuration here

Run sbt and try  one or more of the examples and then:

  1. ``` shell
  2. sbt:root> project examples
  3. sbt:skuber-examples> run

  4. Multiple main classes detected, select one to run:

  5. [1] skuber.examples.customresources.CreateCRD
  6. [2] skuber.examples.deployment.DeploymentExamples
  7. [3] skuber.examples.fluent.FluentExamples
  8. [4] skuber.examples.guestbook.Guestbook
  9. [5] skuber.examples.ingress.NginxIngress
  10. [6] skuber.examples.job.PrintPiJob
  11. [7] skuber.examples.list.ListExamples
  12. [8] skuber.examples.patch.PatchExamples
  13. [9] skuber.examples.podlogs.PodLogExample
  14. [10] skuber.examples.scale.ScaleExamples
  15. [11] skuber.examples.watch.WatchExamples

  16. Enter number:
  17. ```

For other Kubernetes setups, see the configuration guide for details on how to tailor the configuration for your clusters security, namespace and connectivity requirements.

Prerequisites


Java 8
Kubernetes cluster

A Kubernetes cluster is needed at runtime. For local development purposes, minikube is recommended. To get minikube follow the instructions here

Release


You can use the latest release (for 2.12 or 2.13) by adding to your build:

  1. ``` scala
  2. libraryDependencies += "io.skuber" %% "skuber" % "2.6.7"
  3. ```

Meanwhile users of skuber v1 can continue to use the final v1.x release, which is available only on Scala 2.11:

  1. ``` scala
  2. libraryDependencies += "io.skuber" % "skuber_2.11" % "1.7.1"
  3. ```

NOTE: Skuber 2 supports Scala 2.13 since v2.4.0 - support for Scala 2.11 has now been removed since v2.6.0.

Migrating to release v2


If you have an application using the legacy version v1 of Skuber and want to move to v2, then check out the migration guide.

Building


Building the library from source is very straightforward. Simply run sbt test in the root directory of the project to build the library (and examples) and run the unit tests to verify the build.

License


This code is licensed under the Apache V2.0 license, a copy of which is included here.

IMPORTANT: Akka License Model Changes


Lightbend have moved Akka versions starting from 2.7.x from an Apache 2.0 to BSL license. Skuber currently uses Akka 2.6.x and it is not planned to move to a BSL licensed Akka version - instead it is planned to migrate Skuber to the Apache Pekko open-source fork once it has a full release.
Last Updated: 2023-09-03 19:17:54