Kubeclient

A Ruby client for Kubernetes REST api. The client supports GET, POST, PUT, DELETE on pods, services and replication controllers. Also, GET and DELETE is supported for nodes. The client currently supports Kubernetes REST api version v1beta1.

Installation

Add this line to your application's Gemfile:

gem 'kubeclient'

And then execute:

$ bundle

Or install it yourself as:

$ gem install kubeclient

Usage

Please note that all the properties in json objects are converted to ruby style in the client (and converted back to k8s side before sent to k8s). So, containerPort on k8s side is container_port in the client. resourceVersion --> resource_version

Initialize the client:
client = Kubeclient::Client.new 'http://localhost:8080/api/' , "v1beta1"

Examples:

  1. Get all pods (and respectively: get_services, get_nodes, get_replication_controllers)
    pods = client.get_pods

  2. Get a specific node (and respectively: get_service "service id" , get_pod "pod id" , get_replication_controller "rc id" )
    node1 = client.get_node "127.0.0.1"
    Note - Kubernetes doesn't work with the uid, but rather with the 'id' property. Querying with uid causes 404.

  3. Delete a service (and respectively delete_pod "pod id" , delete_replication_controller "rc id", delete node "node id")
    Input parameter - id (string) specifying service id, pod id, replication controller id.
    client.delete_service "redis-service"

  4. Create a service (and respectively: create_pod pod_object, create_replication_controller rc_obj)
    Input parameter - object of type Service, Pod, ReplicationController
    service = Service.new
    service.id = "redis-master"
    service.port = 6379
    service.container_port = "redis-server"
    service.selector = {}
    service.selector.name = "redis"
    service.selector.role = "master"
    client.create_service service

  5. Update entity (update pod, service, replication controller)
    Input parameter - object of type Service, Pod, ReplicationController
    client.update_service service1

  6. Get all entities - Returns a hash with 4 keys (node, service,pod, replication_controller). Each key points to an EntityList of same type. This method is a convenience method instead of calling each entity's get method separately.
    client.get_all_entities

Contributing

  1. Fork it ( https://github.com/[my-github-username]/kubeclient/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Tests

This client is tested with Minitest. Please run all tests before submitting a Pull Request, and add new tests for new functionality.

Running tests:
rake test