GithubHelp home page GithubHelp logo

oscaro / clj-k8s Goto Github PK

View Code? Open in Web Editor NEW
9.0 4.0 0.0 664 KB

A fully featured Clojure wrapper for the Kubernetes API

Home Page: https://oscaro.github.io/clj-k8s/

Clojure 99.92% Shell 0.08%
clojure kubernetes

clj-k8s's Introduction

clj-k8s Clojure With Minikube Clojars Project

A Clojure Wrapper for the kubernetes API.

See OpenAPI specification for more information.

Generating Stubs

Stubs are generated with OpenAPIGenerator from OpenAPI 2.0/3.x Kubernetes API definition

# Check your kubernetes version:

$ kubectl version -o yaml
clientVersion:
  gitVersion: v1.26.1
  platform: linux/amd64
serverVersion:
  gitVersion: v1.26.1

$  bin/openapi-generate
[...]

$ git diff

API Usage

Creating client instance

Client is modelized by a map, initialization function depend of your Kubernetes distribution.

(ns test
  (:require [clj-k8s.auth :as ka]))

;; From ServiceAccount
(def client (ka/from-service-account))

;; From GKE
(def client (ka/from-gcp-kube-config))

;; From Env
(def client (ka/from-token))

;; The default & Generic way
(def client (ka/from-spec {:base-url "https://localhost:6443"
                           :token "eyGteo8o..."
                           :namespace "wilkins"}))

Special Notes

  • For GKE, the KUBECONFIG env variable is honored and ~/.kube/config used as fallback if path isn't set via argv.
  • For environment variable, the K8S_TOKEN should be setup if not provided by argument

The Authentification method is subjected to change in the future, with a generic function for context resolving. We recommand using the from-spec method for the moment.

API Methods

Namespaces

(require [clj-k8s.api :as k])

(k/get-namespace client "default")
(k/create-namespace client "foobar")
(k/delete-namespace client "foobar")

Testing

Setup Minikube

Setup a minikube cluster and setup token & environnement variables as follow:

$ source bin/source-minikube

$ echo $KUBERNETES_TOKEN
ey...

Create API Token

kubectl -n kube-system create serviceaccount toast
kubectl -n kube-system create clusterrolebinding toast-bind --clusterrole=cluster-admin --serviceaccount=kube-system:toast
export K8S_TOKEN=$(kubectl -n kube-system create token toast)

Lauching tests

When token is properly exported, run tests as follow:

lein test

License

Copyright © 2019-2023 Oscaro

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

clj-k8s's People

Contributors

iomonad avatar

Stargazers

Ulan Sametov avatar Dimitris Mostrous avatar Pavel avatar Joseph Avila Alvarez avatar li feng avatar Oleg Pykhalov avatar Ed Porras avatar Mathieu MARCHANDISE avatar  avatar

Watchers

Sébastien Aperghis-Tramoni avatar Germain Maurice avatar Mathieu MARCHANDISE avatar Rousseau Baptiste 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.