Project

k-tools

0.0
No commit activity in last 3 years
No release in over 3 years
KTools is used to help manage, deploy and debug applications on Kubernetes environments.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
~> 10.0
~> 3.0

Runtime

~> 0.8.1
~> 3.7
~> 0.12.2
 Project Readme

ktools

A.k.a. kt or 'kate'.

It's a CLI program that helps interacting with Kubernetes clusters from a developer perspective.

Originally it was a group of separated Bash scripts, but due to the increasing complexity and Shell incompatibility issues, I've decided to rewrite everything as a single Ruby program.

It features:

  • Support for Staging and Production environments.
  • Management of different cluster credential connections.
  • Management of K8s application Docker image registry secrets.
  • Management of K8s application configMaps.
  • Management of K8s application NGINX ingresses.
  • Removing (pruning) an entire application.
  • Application force deployment.
  • Application Bash login.
  • Application logs reading/live-streaming.
  • Impress your dog.
  • Impress your cat.

See our CHANGELOG.

Requirements

Before going any forward, you need to have:

* Only tested with Ruby v2.5.1. I recommend using asdf to install it.

Important Note A: You will also need to place your .yaml DO K8s credential files into your ~/.kube path. (Create this directory if don't exist). If you don't have them, ask your cluster admin for one. It shall be one for Staging and other for Production (It also contains your token for accessing the K8s dashboard).

Important Note B: A updated secrets repository is also needed. If you don't have one, check the folder secrets-sample in this repository, it's a sample on how to setup one for your company. If you are a Foxbox developer, ask the cluster admin how to get access to it. If you already have access, just clone it to your machine.

Important Note C: In this document, whenever you see the word appslug, it means you must replace it by the application slug you are operating in. Like my-awesome-project. And whenever you see the word environment, you must replace by the cluster environment you are operating in. Like staging or production.

Installation

$ gem install k-tools

This will add the $ kt (kate) executable to your system.

Usage

$ kt Setup/Init

After installing, start the init by:

$ kt

It will ask for your secrets repository path.

Enter it and then you're done.

Note: If you want to re-run the init and reconfigure your secrets repository path, just run:

$ kt setup

swap tool

This command enables you to list and to connect to different K8s clusters. In our case we will use it for switching between Staging and Production connections, but you can use it to manage how many credentials you want.

You can use it from any path in your terminal.

Listing Kubernetes clusters/connections

$ kt swap
- foxbox-production-admin
- fs-orc
- st-orc
-> foxbox-staging-devops
- foxbox-staging-admin
- orc-admin
- foxbox-production-devops

Check the -> pointing to the current connected cluster account. In my case I have a bunch of accounts/clusters. To edit their names just change the name of the .yaml files at your ~/.kube/ path.

You may have one foxbox-staging.yaml and other foxbox-production.yaml file, so in this case, $ kt swap will show:

$ kt swap
- foxbox-production
- foxbox-staging

It's pointing to none. That means you haven't connected yet. To do so, simply:

$ kt swap foxbox-staging
Swapped to foxbox-staging.

And now your kubectl is connected to the Staging cluster/account.

You can check with:

$ kt swap
- foxbox-production
-> foxbox-staging

In terminals with such support, the connected cluster/account will be displayed with a yellowish color.

Important Note: That's what dictates on what environment your commands will take place. Be aware! Kate will ask you confirmation for some commands, but your attention is crucial, especially if you have access to Production environments.

spy tool

That's the tool which interacts with your secrets repository copy. It will help you managing configMap, ingress, registry secrets and removing entire applications from a cluster.

You can run those commands from anywhere in your system.

Deleting a Docker registry K8s secret

Just:

$ kt spy drop registry appslug

Creating a Docker registry K8s secret

Remember that it will use the state described inside the files of your secrets repository copy. Check this section if you are confused. (Foxbox developers only)

Find them at: environment/appslug/registry.json. (Of your secrets repository)

Once you edited the changes, just:

$ kt spy create registry appslug environment

Warning: Note you are not updating, you are creating!

Deleting a K8s application configMap

Just:

$ kt spy drop config appslug

Updating/Creating a K8s application configMap

The same principle of the Docker registry files applies to the configMaps at your secrets repository.

Find them at: environment/appslug/config_map.yml.

And to update/create, just:

$ kt spy apply config appslug environment

Deleting a K8s application ingress

Just:

$ kt spy drop ingress appslug

Updating/Creating a K8s application ingress

Same principle here too.

Find them at: environment/appslug/ingress.yml.

To update/create, just:

$ kt spy apply ingress appslug environment

Deleting a entire K8s application

WARNING: This will destroy everything related to the given app at the current connected cluster.

Just:

$ kt spy drop all appslug

deliver tool

This tool helps with debugging a running application.

deliver commands must be executed inside the application's path.

Important Note: This tool requires your application to have a copy of the kdeliver executable at its root path. You can find it here at this repo too. (Make sure to set permissions to run)

Forcing deployment of a application

$ kt deliver force deploy

Entering a running application pod's Bash

$ kt deliver get bash appslug

Downloading running application logs

$ kt deliver get logs appslug

Watching the log-stream of running application

$ kt deliver get logs appslug --tail

Reporting Bugs

Just open a issue.

If you know how to fix and works at Foxbox, please open a PR.

License

The gem is available as open source under the terms of the MIT License.