Skip to main content

Fabfiles and Kubernetes: Automating SSH with Kubernetes Nodes

While Kubernetes is ushering in a world where SSH is less necessary on a daily basis for deploying and managing applications, there are still instances when SSH is necessary for gathering statistics, debugging issues, and repairing configuration issues. So, while years from now there may not be a need to SSH and run one-off debugging sessions, the tools below are useful for quickly SSH'ing into machines in your Kubernetes cluster.

Kubernetes has a database of nodes in the cluster which can be queried with kubectl get nodes. This is a powerful database for automation and integration with existing tools. One powerful tool is the Fabric SSH utility, which is known as a

Getting Started

Install the Fabric SSH utility and test it:

$ fab --version  
Fabric 1.13.1

Git clone this repo and move into the directory:

git clone
cd fabric-kubernetes-nodes

Fabric will use the from the root of this directory. So now Kubernetes Nodes and labels are integrated directly into fabric! Here is an example session using this integration:

$ kubectl label node my-special-label=true  
$ fab -u core -R my-special-label=true -- date  
[] Executing task '<remainder>'  
[] run: date  
[] out: Thu Feb 16 06:54:37 UTC 2017  
[] out:</remainder>

Demo of fabric integration

Bastion or Gateway Hosts

Many configurations of Kubernetes, like CoreOS Tectonic, do not enable direct SSH access to machines in the cluster, and instead users must first access gateway or bastion hosts. If the Kubernetes cluster has this configuration, add the --gateway flag to the command and change the address type to InternalIP.

$ fab --gateway=W.X.Y.Z -u core -R -- date  
[] Executing task '<remainder>'  
[] run: date  
[] out: Mon May 1 02:50:13 UTC 2017  
[] out:</remainder>

[] Executing task '<remainder>'  
[] run: date  
[] out: Mon May 1 02:50:16 UTC 2017  
[] out:</remainder>


By default the fabfile will use the ExternalIP of nodes. However, it can be configured to use any IP address that a Node has available. The example above uses the common InternalIP field. To change this to a custom SpecialIP export the environment variable FAB_KUBE_NODE_ADDRESS_TYPE=SpecialIP.

To find out more about the Fabric integration with Kubernetes, check out the GitHub repository.

If you have any questions about Fabric or any other aspect of Kubernetes and other CoreOS open source projects, ask the team directly at CoreOS Fest! The Kubernetes and distributed systems conference takes place May 31 and June 1 in San Francisco - join us for two days of talks from the community on the latest developments in the open source container ecosystem. Register today.