Book Image

Kubernetes - A Complete DevOps Cookbook

By : Murat Karslioglu
Book Image

Kubernetes - A Complete DevOps Cookbook

By: Murat Karslioglu

Overview of this book

Kubernetes is a popular open source orchestration platform for managing containers in a cluster environment. With this Kubernetes cookbook, you’ll learn how to implement Kubernetes using a recipe-based approach. The book will prepare you to create highly available Kubernetes clusters on multiple clouds such as Amazon Web Services (AWS), Google Cloud Platform (GCP), Azure, Alibaba, and on-premises data centers. Starting with recipes for installing and configuring Kubernetes instances, you’ll discover how to work with Kubernetes clients, services, and key metadata. You’ll then learn how to build continuous integration/continuous delivery (CI/CD) pipelines for your applications, and understand various methods to manage containers. As you advance, you’ll delve into Kubernetes' integration with Docker and Jenkins, and even perform a batch process and configure data volumes. You’ll get to grips with methods for scaling, security, monitoring, logging, and troubleshooting. Additionally, this book will take you through the latest updates in Kubernetes, including volume snapshots, creating high availability clusters with kops, running workload operators, new inclusions around kubectl and more. By the end of this book, you’ll have developed the skills required to implement Kubernetes in production and manage containers proficiently.
Table of Contents (12 chapters)

Configuring Red Hat OpenShift

In this recipe, we will learn how to deploy Red Hat OpenShift on AWS, bare-metal, or VMware vSphere VMs.

The steps in the Provisioning an OpenShift cluster recipe can be applied to deploy OpenShift on either VMs running on a virtualized environment or bare-metal servers.

Getting ready

All the operations mentioned here require a Red Hat account with active Red Hat Enterprise Linux and OpenShift Container Platform subscriptions. If you don't have one already, go to and create an account.

When you deploy on VMs, make sure to plan that the zones you create on Kubernetes nodes are actually physically located on separate hypervisor nodes.

For this recipe, we need to have a minimum of six nodes with Red Hat Enterprise CoreOS installed on them. These nodes can be either bare-metal, VMs, or a mix of bare-metal and VMs.

How to do it…

This section will take you through how to configure Red Hat OpenShift. To that end, this section is further divided into the following subsections to make this process easier:

  • Downloading OpenShift binaries
  • Provisioning an OpenShift cluster
  • Connecting to OpenShift clusters

Downloading OpenShift binaries

Make sure you are on the Terminal of your first master and that you have an account with root access, or you are running as a superuser. Follow these steps:

  1. Go to and download the latest OpenShift Installer:
  1. Extract the installer files on your workstation:
$ tar -xzf openshift-install-linux-*.tar.gz

The preceding command will create a file called openshift-install in the same folder.

Provisioning an OpenShift cluster

In this recipe, we will use the AWS platform to deploy OpenShift:

  1. To get your OpenShift cluster up, use the following command:
$ ./openshift-install create cluster
  1. Choose aws as your platform and enter your AWS Access Key ID and Secret Access Key.
  2. Choose your region. In our example, this is us-east-1.
  3. Select a base domain. In our example, this is
  4. Enter a cluster name.
  5. Copy Pull Secret from the Red Hat site and paste it onto the command line:
  1. After the installation is complete, you will see the console URL and credentials for accessing your new cluster, similar to the following:
INFO Install complete!
INFO To access the cluster as the system:admin user when using 'oc', run 'export KUBECONFIG=/home/ubuntu/auth/kubeconfig'
INFO Access the OpenShift web-console here:
INFO Login to the console with user: kubeadmin, password: ABCDE-ABCDE-ABCDE-ABCDE
  1. Switch to the Red Hat site and click on the Download Command-Line Tools link to download openshift-client.
  2. Extract the openshift-client files in your workstation:
$ tar -xzf openshift-client-linux-*.tar.gz && sudo mv oc /usr/local/bin

The preceding command will create the kubectl and oc files on the same folder and move the oc binary to PATH.

Connecting to OpenShift clusters

To connect to OpenShift clusters, follow these steps:

  1. To get access to your OpenShift cluster, use the following command:
$ export KUBECONFIG=~/auth/kubeconfig
  1. Log in to your OpenShift cluster after replacing password and cluster address:
$ oc login -u kubeadmin -p ABCDE-ABCDE-ABCDE-ABCDE \ \

If you prefer to use the web console instead, open the web console URL address from the Provisioning an OpenShift cluster recipe, in step 7.

How it works…

This recipe showed you how to quickly deploy an OpenShift cluster on AWS.

In step 1, we created a cluster using the default configuration of the installer-provisioned infrastructure.

The installer asked a series of questions regarding user information and used mostly default values for other configuration options. These defaults can be edited and customized if needed using the install-config.yaml file.

To see the defaults that were used for the deployment, let's create an install-config.yaml file and view it:

$ ./openshift-install create install-config && cat install-config.yaml

As you can see from the following output, the file's default configuration creates a cluster consisting of three master and three worker nodes:

apiVersion: v1
- hyperthreading: Enabled
name: worker
platform: {}
replicas: 3
hyperthreading: Enabled
name: master
platform: {}
replicas: 3

Edit install-config.yaml as needed. Next time you create the cluster, new parameters will be used instead.

There's more…

It is also useful to have knowledge of the following information:

  • Deleting your cluster

Deleting your cluster

To delete your cluster, use the following command:

$ ./openshift-install destroy cluster

This process will take a few minutes and, when finished, you will get a confirmation message.

See also