0.0
No commit activity in last 3 years
No release in over 3 years
Simple ruby wrapper for `kubectl` commands
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
~> 13.0
~> 3.0
~> 0.17
 Project Readme

Kubecontrol

Simple ruby wrapper for kubectl commands

Installation

Add this line to your application's Gemfile:

gem 'kubecontrol'

And then execute:

$ bundle

Or install it yourself as:

$ gem install kubecontrol

Usage

kubectl Commands
require 'kubecontrol'

# create new client
kubectl_client =  Kubecontrol.client.new

#Exec an kubectl apply command
std_out, std_err, exit_code = kubectl_client.apply(file_path: 'path/to/deployment.yaml')
std_out, std_err, exit_code = kubectl_client.apply(kustomization_dir: 'path/to/kustomization_dir')

#Exec an arbitrary kubectl command
std_out, std_err, exit_code = kubectl_client.kubectl_command 'get deployments'

Pods

require 'kubecontrol'

# create new client
kubectl_client =  Kubecontrol.client.new

# all pods for namespace
pods = kubectl_client.pods

# find pod by name regex
pod = kubectl_client.find_pod_by_name /foo-api-.*/

# access pod information
pod.name
pod.ready
pod.status
pod.restarts
pod.age
pod.namespace

#exec commands on a pod
std_out, std_err, exit_code = pod.exec('ls')

Services

require 'kubecontrol'

# create new client
kubectl_client =  Kubecontrol.client.new

# all services for namespace
services = kubectl_client.services

# find service by name regex
service = kubectl_client.find_service_by_name /foo-api-.*/

# access service information
service.name
service.type
service.cluster_ip
service.external_ip
service.ports
service.age
service.namespace

Deployments

require 'kubecontrol'

# create new client
kubectl_client =  Kubecontrol.client.new

# all deployments for namespace
deployments = kubectl_client.deployments

# find deployment by name regex
deployment = kubectl_client.find_deployment_by_name /foo-api-.*/

# access deployment information
deployment.name
deployment.ready
deployment.up_to_date
deployment.available
deployment.age
deployment.namespace

# is deployment ready
deployment.ready?
deployment.all_ready?

# is deployment available
deployment.available?

# is deployment up_to_date
deployment.up_to_date?

# scale deployment
deployment.scale(5)

StatefulSets

require 'kubecontrol'

# create new client
kubectl_client =  Kubecontrol.client.new

# all stateful_sets for namespace
stateful_sets = kubectl_client.stateful_sets

# find stateful_set by name regex
stateful_set = kubectl_client.find_stateful_set_by_name /foo-api-.*/

# access stateful_set information
stateful_set.name
stateful_set.ready
stateful_set.age
stateful_set.namespace

# is stateful_set ready
stateful_set.ready?
stateful_set.all_ready?

# scale stateful_set
stateful_set.scale(5)

Secrets

require 'kubecontrol'

# create new client
kubectl_client =  Kubecontrol.client.new

# all secrets for namespace
secrets = kubectl_client.secrets

# find secret by name regex
secret = kubectl_client.find_secret_by_name /foo-api-.*/

# access secret information
secret.name
secret.type
secret.data
secret.age
secret.namespace

# access secret data values
secret.data_values
secret.data_values['user']
secret.data_values['password']

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/marcoadkins/kubecontrol.

Contributors