kubernetesset-kubernetes-cluster-oracle

Set Up a Kubernetes Cluster on Oracle Cloud Infrastructure Classic

Introduction

Oracle Cloud Infrastructure Classic is an enterprise-grade cloud platform designed for rapid development and deployment of web applications. It allows organisations to reduce deployment costs and simplify their IT infrastructure. Business users can host and scale enterprise websites and complex web applications securely and efficiently.

Many developers choose containers as a way to develop applications because of its ease and cost-effectiveness in container application deployments. When the application needs increase and you need to automate the deployment and management of these application containers in the cloud, a new platform comes in: Kubernetes. This guide walks you through the process of creating a cluster in Oracle Cloud Infrastructure Classic (comprising one master instance and two nodes) and the setup of Kubernetes in order to orchestrate application deployments across the cluster.

Assumptions and Prerequisites

This guide focuses on installing and configuring a Kubernetes cluster on Oracle Cloud Infrastructure Classic. To do this, you will create three instances (one master and two nodes) on Oracle Cloud Infrastructure Classic, then you’ll create the cluster by joining those instances using Kubernetes.

This guide makes the following assumptions:

To create a Kubernetes cluster in Oracle Cloud Infrastructure Classic you will typically follow these steps:

  • Step 1: Configure basic networking rules
  • Step 2: Add a public SSH key
  • Step 3: Launch the instances
  • Step 4: Create storage for volumes
  • Step 5: Install Kubernetes and set it up using kubeadm

Step 1: Configure basic networking rules

By default, no instance has public access. For the sake of simplicity, this tutorial shows you how to enable HTTP and SSH access to all the cluster nodes. To do that, you need to create a security list and then, create the security rules that you want to associate with the previously created list. Follow these instructions to begin the process:

  • Log in to Oracle Cloud Infrastructure Classic with your domain account (in case you are not already logged in).

  • Once logged in to the platform, select the “Dashboard” tab and then click the “Open Service console” link for the Oracle Compute Cloud service. Make sure that you have selected the desired domain by checking the “Identity Domain” located in the upper right corner of the screen.

    Open Service console

  • Navigate to the top menu and select the “Network” option. Follow the steps below to create both a security list and the associated security rules.

    Network panel

Create a security list

  • In the left side menu of the “Network” section, click the “Shared Networks -> Security Lists” option.

    Create a Security List

  • Click the “Create Security List” button located on the right side of the screen.

  • Add a name for your security list (kube-cluster in the current example) and click “Create”.

    Create a Security List

Create security rules

In this step, we are going to create two different security rules: one for enabling HTTP access and another for enabling SSH access.

  • In the left side menu of the “Network” section, click the “Shared Networks -> Security Rules” option.

    Create a Security rule

To create the security rule to enable HTTP access:

  • Click the “Create Security Rule” button located on the right side of the screen.

  • Fill the required information as follows, then click on “Create”.

    • Set the name.
    • Security application: http.
    • “Source -> Security IP List”: “public-internet” for allowing access from anywhere.
    • “Destination -> Security List”: the security list you previously created.

    Create HTTP Security rule

  • Repeat the same process to create the security rule for enabling SSH access. Fill the required information as follows, then click on “Create”:

    • Set the name.
    • Security application: ssh.
    • Source -> Security IP List: “public-internet” for allowing access from anywhere.
    • Destination -> Security List: the security list you previously created.

    Create SSH Security rule

Step 2: Add a public SSH key

In order to connect to your instances via SSH, you need to add your public SSH key before launching the master and node instances. Otherwise, you won’t be able to connect to them from your local terminal to configure the cluster.

  • In the left side menu of the “Network” section, click the “SSH Keys” option.

    Add an SSH Key

  • Click the “Add SSH Key” button located on the right side of the screen.

  • Introduce a name for your key (my-key in this example), by pasting your SSH public key in the box below or browsing to your files in order to add it. Leave the “Enabled” checkbox activated. Then, click the “Add” button.

    Add an SSH Key

Step 3: Launch the instances

The next step consists of creating three instances that will be joined in step 5 in order to create a cluster: one for the master node and two for the slave nodes.

All of the nodes will be launched using the Ubuntu Server 16.04 image. In the current example the nodes will be named “master”, “node1” and “node2”, respectively. This section shows the process of creating the master node. Please repeat these steps for each instance you want to launch.

Follow the steps below to create and setup an instance:

  • Navigate to the top menu and select the “Instances” option.

    Instances menu

  • Click the “Create Instance” button located on the right side of the screen. You will see the “Image” section.

  • In the left menu, click on “Marketplace”.

  • Enter “ubuntu” in the searching box and select the Ubuntu Server 16.04-LTS amd64 image as shown below:

    Select Ubuntu image

  • In the resulting window, accept the “Oracle Standard Terms and Restrictions” and click the “Install” button.

    Install Ubuntu image

The next step is to add the SSH key and the Security list to the instance. To do this, follow the instructions below:

  • Click on the “Instance” option in the top menu.

  • In the resulting screen, fill the required information as follows:

    • Set instance name (in the current example, “master”. Repeat these steps for “node1” and “node2”).
    • Public SSH Keys: enter the name of the ssh key you have created in the previous step.

    Setup the instance

  • Click the “Network” option in the top menu.

  • Add the Security list you have previously created. (In the current example “kube-cluster”). Then, click the “Review and Create” button.

    Setup the instance

  • Review the instance properties and click on “Create”.

    Setup the instance

    NOTE: Remember to repeat the instructions above in order to create the two slave nodes.

After creating all the instances (it will take several minutes), you should see the following in the “Instances” section:

Instances of the cluster

To see detailed information about any instance, double-click on it or select the “View” option in the right menu of the selected instance:

Instances of the cluster

You should see detailed information about the recently created instance:

Instance information

Step 4: Create storage for volumes (optional)

NOTE: If you want to use persistent volumes in your cluster, you need to create a storage provisioner in at least one cluster node. This step is optional, so skip it if doesn’t apply.

Follow the steps below to create storage volumes attached to an instance:

  • Navigate to the top menu and select the “Storage” option.

    Create Storage for volumes

  • Click the “Create Storage Volume” button located on the right side of the screen. You will see a pop-up window.

  • Enter the name and size. In the current example we have selected 50GB. (The more storage you allocate for your volumes, the more deployments you can make). Then, click on “Create”.

    Create Storage for volumes

Once you’ve created the storage volume you need to attach it to the instance (in this case, it will be attached to the “node1” instance). To do so:

  • Navigate to the storage list and select the list you’ve recently created. Open the storage options menu (right-hand side) and select the “Attach to Instance” option.

  • Select the instance you want to attach (in the current example, “node1”) and click on “Attach to instance”.

    Attach storage volume to an instance

Step 5: Install Kubernetes and set it up using kubeadm

Follow the instructions below to install and configure Kubernetes. The last step is to join the nodes to the recently created cluster.

Configure the master node

The first step consists of installing Kubernetes and setting it up in the master node using kubeadm. Follow the steps below to configure the master node. It will then be ready for the other nodes to join it.

  • Open a terminal in your computer and log in to the master node via SSH. KEYFILE and MASTER-PUBLIC-IP are placeholders for the path to your public key file and the public IP of the master node, respectively. Remember to replace them with the right values:

    $ ssh -i KEYFILE ubuntu@MASTER-PUBLIC-IP
    
  • Add Kubernetes PPA repositories to make the Kubernetes and kubeadm packages available:

    $ sudo apt-get update && sudo apt-get install -y apt-transport-https
    $ curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list deb http://apt.kubernetes.io/ kubernetes-xenial main EOF
    
  • Update the APT repositories to make the packages available:

    $ sudo apt-get update
    
  • Install Docker and kubeadm:

    $ sudo apt-get install -y docker-engine kubelet kubeadm kubectl kubernetes-cni
    
  • Init kubeadm. This command will show you how to connect a slave to the cluster. Copy the output and save it in a safe place. In the next step, you’ll need it to join the other nodes to the cluster:

    $ sudo kubeadm init --pod-network-cidr=10.244.0.0/16
    
  • Configure the kubectl CLI:

    $ mkdir -p .kube
    $ sudo cp /etc/kubernetes/admin.conf "$HOME/.kube/config"
    $ sudo chown "$(id -u):$(id -g)" "$HOME/.kube/config"
    
  • Install flannel overlay to create a pod network:

    $ kubectl create -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel-rbac.yml
    $ kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
    

    NOTE: There are many types of overlay network that allow you to create a network for pods communication. This example uses flannel overlay, choose the one you prefer.

  • Enable the ingress controller to allow inbound connections to reach the cluster services:

    $ kubectl apply -f https://gist.githubusercontent.com/javsalgar/4a89fc20f0c10b7f6e1f17fed6130c7c/raw/bb5b4da2ca3518d5df0e43d1ac02dd0f763e4aec/ingress-rbac # RBAC
    $ kubectl apply -f https://rawgit.com/kubernetes/ingress/master/examples/deployment/nginx/kubeadm/nginx-ingress-controller.yaml
    

At this point you have the master node configured and ready for other nodes to join.

Configure the slave nodes

The next step is to configure the slave nodes so they are ready to join the master. Follow the steps below. Repeat the process for every node you want to connect to the cluster.

  • Open a terminal on your computer and log in to the node via SSH. KEYFILE and NODE-PUBLIC-IP are placeholders for the path to your public key file and the public IP of the node, respectively. Remember to replace them with the right values:

    $ ssh -i KEYFILE ubuntu@NODE-PUBLIC-IP
    
  • Add Kubernetes PPA repositories:

    $ sudo apt-get update && sudo apt-get install -y apt-transport-https
    $ curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list deb http://apt.kubernetes.io/ kubernetes-xenial main EOF
    
  • Update APT repositories:

    $ sudo apt-get updatesudo apt-get update
    
  • Install Docker and kubeadm:

    $ sudo apt-get install -y docker-engine kubelet kubeadm kubectl kubernetes-cni
    
  • Use the join command to complete the cluster configuration. TOKEN AND NODE-PUBLIC-IP:PORT are placeholders. Remember to replace them by pasting the command you have obtained by running the kubeadm command.

    $ sudo kubeadm join --token TOKEN NODE-PUBLIC-IP:PORT
    

Congratulations! You have installed and configured a 3-node Kubernetes cluster on Oracle Cloud Infrastructure Classic.

Now you have your Kubernetes cluster deployed and configured it is time to learn how to deploy an application on it. The following video shows the steps for deploying a Python application in a cluster running on Oracle Cloud Infrastructure Classic: