Use Kubectl to Manage a 1&1 Container Cluster

Table of Contents

Introduction

Learn how to install and use Kubectl on a Linux machine in order to manage a CaaS cluster. Kubectl is a command-line tool for deploying and managing applications on Kubernetes.

Requirements

  • A 1&1 Container Cluster
  • A Linux machine, either a desktop, a stand-alone Linux server, or a Cloud Server (any distribution).

Install Kubectl on the Desktop, Server, or Cloud Server

The first step is to install Kubectl on the Linux desktop, server, or Cloud Server which you plan to use to manage the Kubernetes cluster.

The easiest way to install Kubectl is with curl. If curl is not available on your system, install it with the command:

sudo apt-get install curl

Download the Kubectl binary with the command:

curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl

Set the permissions for the file:

chmod +x ./kubectl

Move the file into your PATH:

sudo mv ./kubectl /usr/local/bin/kubectl

Verify the installation:

kubectl version

It should respond with the version information:

[jdoe@localhost ~]# kubectl version
Client Version: version.Info{Major:"1", Minor:"6", GitVersion:"v1.6.2", GitCommit:"477efc3cbe6a7effca06bd1452fa356e2201e1ee", GitTreeState:"clean", BuildDate:"2017-04-19T20:33:11Z", GoVersion:"go1.7.5", Compiler:"gc", Platform:"linux/amd64"}
The connection to the server localhost:8080 was refused - did you specify the right host or port?

Configure Kubectl

Kubectl will need to be configured in order to connect to your 1&1 Container Cluster. Download the Kubeconfig file for your 1&1 Container Cluster by following the instructions in the article Download a 1&1 Container Cluster Kubeconfig File.

Go to your home directory:

cd

Create the .kube directory with the command:

mkdir .kube

If your managing computer is a Linux desktop, rename the kubeconfig file to config and move it into the ~/.kube directory.

If your managing computer is a Linux server or Cloud Server, there are two options for adding the configuration file:

  1. Use FTP to upload the kubeconfig file into the ~/.kube directory, then rename the file config.
  2. Create the file on the server and paste in the contents.

To do this, create the file:

nano .kube/config

On your desktop computer, open the kubeconfig file with a plaintext editor such as Notepad. Select all, then copy and paste the contents into the config file. (Note: Use Shift + Insert to paste into a PuTTY shell session.)

Save and exit the file.

After adding the Kubeconfig file to the managing computer, verify that Kubectl is configured correctly with the command:

kubectl cluster-info

It should respond with the information for your CaaS cluster:

[jdoe@localhost .kube]$ kubectl cluster-info
Kubernetes master is running at https://192.168.0.1:6443
Heapster is running at https://192.168.0.2:6443/api/v1/proxy/namespaces/kube-system/services/heapster
KubeDNS is running at https://192.168.0.2:6443/api/v1/proxy/namespaces/kube-system/services/kube-dns

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

Using Kubectl

The kubectl command can be used to manage most aspects of the 1&1 Container Cluster. An overview of kubectl along with command examples can be found in the official Kubernetes user guide.

Some common kubectl commands include:

Create a service from the file example.yaml

kubectl create -f example.yaml

Create a replication controller from example-controller.yaml

kubectl create -f example-controller.yaml

List all pods

kubectl get pods

List all replication controllers and services

kubectl get rc,services

Show a node's details

kubectl describe nodes [node name]

Show a pod's details

kubectl describe pods/[pod name]

Run a command in a container

kubectl exec [pod name] [command]

For example, to run the command date from a container in pod restless-wave, the command is:

kubectl exec restless-wave date

This command will run on the first available container in the pod.

Attach to a container in a pod

kubectl exec -ti [pod name] /bin/bash

This will open an interactive TTY on the first available container in the pod.

View a pod's logs

kubectl logs [pod name]

Comments

Tags: CaaS / Containers