Giter VIP home page Giter VIP logo

skuber's Introduction

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

The client supports v1.0, v1.1 and v1.2 of the Kubernetes API, so should work against all supported Kubernetes releases in use today.

Prerequisites

There is currently no release version, so the following sections assume you have locally cloned this repository and installed the following (if not already installed):

  • sbt version 0.13 or later
  • Java 8

Quick Start

The quickest way to get started with Skuber:

  • If you don't already have Kubernetes installed, then follow the instructions here. This should establish a cluster listening for API requests on port 8080 on the local host, which is the configuration Skuber assumes by default.

  • Try one or more of the examples: run sbt in the skuber top-level directory to start sbt in interactive mode and then:

    > project examples

    > run
    [warn] Multiple main classes detected.  Run 'show discoveredMainClasses' to see the list

    Multiple main classes detected, select one to run:

    [1] skuber.examples.deployment.DeploymentExamples
    [2] skuber.examples.fluent.FluentExamples
    [3] skuber.examples.guestbook.Guestbook
    [4] skuber.examples.scale.ScaleExamples
    [5] skuber.examples.ingress.NginxIngress

    Enter number: 

For non-default setups, see the Configuration guide for details on how to tailor the configuration for your clusters security, namespace and connectivity requirements.

Building

Although there isn't yet a release version of skuber, building the library from source is very straightforward. Simply run sbt testin the root directory of the project to build the library (and examples) and run the unit tests to verify the build.

You can then import the library jar you just built into your project e.g. by copying it into your projects lib folder.

Example Usage

The code block below illustrates the simple steps required to create a replicated nginx service on a Kubernetes cluster that can be accessed by clients (inside outside the cluster) at a stable address.

It creates a Replication Controller that ensures five replicas (pods) of an nginx container are always running in the cluster, and exposes these to clients via a Service that automatically proxies any request received on port 30001 on any node of the cluster to port 80 of one of the currently running nginx replicas.

import skuber._
import skuber.json.format._

val nginxSelector  = Map("app" -> "nginx")
val nginxContainer = Container("nginx",image="nginx").exposePort(80)
val nginxController= ReplicationController("nginx",nginxContainer,nginxSelector)
	.withReplicas(5)
val nginxService = Service("nginx")
	.withSelector(nginxSelector)
	.exposeOnNodePort(30001 -> 80) 

import scala.concurrent.ExecutionContext.Implicits.global

val k8s = k8sInit

val createOnK8s = for {
  svc <- k8s create nginxService
  rc  <- k8s create nginxController
} yield (rc,svc)

createOnK8s onComplete {
  case Success(_) => System.out.println("Successfully created nginx replication controller & service on Kubernetes cluster")
  case Failure(ex) => System.err.println("Encountered exception trying to create resources on Kubernetes cluster: " + ex)
}

k8s.close

Features

  • Comprehensive Scala case class representations of Kubernetes kinds (e.g. Pod, Service etc.)
  • Complete JSON support for reading and writing Kubernetes kinds.
  • Support for Kubernetes object, list and simple kinds
  • Support for create, get, delete, list, update, and watch methods on Kubernetes resources.
    • Asynchronous methods (i.e. the methods return their results in Futures)
    • Each method is implemented by a corresponding HTTP request to the Kubernetes API server
    • Strongly-typed API e.g. k8s get[Deployment]("myDepl") returns a value of type Future[Deployment]
  • Support for full core Kubernetes API group
  • Support for the extensions API group (e.g. HorizontalPodAutoScaler,Ingress)
  • Fluent API for building / modifying the desired specification (spec) of a Kubernetes resource
  • Watching Kubernetes objects and kinds returns Iteratees for reactive processing of events from the cluster
  • Highly configurable via kubeconfig files or programmatically
  • Full support for label selectors
    • includes a mini-DSL for building expressions from both set-based and equality-based requirements.

See the programming guide for more details.

Status

The coverage of the core Kubernetes API functionality by Skuber is extensive.

Support of more recent extensions group functionality is not yet entirely complete: full support (with examples) is included for Deployments, Horizontal pod autoscaling and Ingress / HTTP load balancing; support for other Extensions API group features including Daemon Sets and Jobs is expected shortly.

License

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

skuber's People

Contributors

doriordan avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.