Skip to content

Latest commit

 

History

History
executable file
·
175 lines (145 loc) · 7.4 KB

File metadata and controls

executable file
·
175 lines (145 loc) · 7.4 KB

Create Free tier Kubernetes Cluster on a IBM Cloud Trial Account

This article discuss the steps to create a Kubernetes cluster and deploy a web application.

Prerequisites

  • An IBM Cloud account, to sign up visit this site.

Creating a Kubernetes Cluster

Steps

  1. Log in to IBM Cloud.
  2. In the top navigation, select Catalog.
    Catalog
  3. Select the category Containers.
    Category Containers
  4. Select Kubernetes Service.
    Kubernetes Service
  5. Under the Plan details section, select Free tier cluster.
    Free tier cluster
  6. Click the Create button.
  7. The Overview page for the cluster will appear. From here you may monitor the creation process, which will take up to 30 minutes to complete.
  8. Once the cluster has been created, green checks will appear across the status tiles.
    Green checks

Accessing the Kubernetes cluster

Once the cluster has been completed

There are several methods available to access the cluster, the following most popular options:

  • CLI (ie command line)
  • the Kubernetes dashboard

In this article you will use both the IBM Cloud Shell and Kubernetes dashboard.

Connect to the IBM Cloud Shell

Steps

  1. In the top navigation, click the button with the Terminal icon. A new browser tab opens titled IBM Cloud Shell.

    Terminal
  2. Back in our cluster Overview tab, select Actions > Connect via CLI.

    Connect to CLI
  3. In the Connect to CLI dialog, run the referenced 3 commands in the IBM Cloud Shell tab.

    Dialog

    Example output:

    Dialog

Connect to the Kubernetes dashboard

Steps

  1. Under the top navigation, click the Kubernetes dashboard button.
    Dialog
  2. A new browser tab opens titled {cluster name} - Kubernetes dashboard.

Accessing Applications Over the Web

By default, the free tier of the Kubernetes lacks features available in the standard cluster.

To provide web access to applications, you will make use of the following:

  • The External-IP address assigned to the single node in our cluster.
  • To provide a hostname to our cluster, we will use nip.io.

    Note: The hostname will be in the format {External-IP}.nip.io.

  • To provide an ingress to our application you will use Nginx Ingress Controller.

    Note: Since we have a single-node cluster, we will use the DaemonSet deployment option which will bind the ingress controller to the External-IP assigned to the node.

Steps:

  1. To install the ingress controller, run the following command:
    kubectl apply -f https://raw.githubusercontent.com/Call-for-Code/Developer-Resources/main/IBM-Cloud-Kubernetes-Cluster/assets/manifests/nginx-ingress-controller-daemon-v3.0.2.yaml
    
  2. To monitor progress, run the following command:
    kubectl get daemonset -n nginx-ingress
    
    Example output:
    NAME            DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE
    nginx-ingress   1         1         1       1            1           <none>          24h
    
  3. To determine the External-IP of the node, run the following command:
    kubectl get nodes -o jsonpath='{.items[0].status.addresses[?(@.type=="ExternalIP")].address}'
    
    Example output:
    169.169.169.169
    
  4. That's it! When creating an ingress, be sure to use the following hostname format:
    {External-IP}.nip.io
    
    Example:
    169.169.169.169.nip.io
    

Deploying a sample application

In this exercise, you will create an application using the Docker image nginxdemos.

Steps:

  1. Connect to the IBM Cloud Shell.

    Note: Refer to the section Connect to the IBM Cloud Shell

  2. First let's create a new namespace. To do so, run the following command:
    kubectl create ns callforcode
    
  3. Let's set callforcode as our default namespace. To do so, run the following command:
    kubectl config set-context --current --namespace=callforcode
    
  4. Now let's create an application based on the nginx-demos image. To do so,run the following command::
    kubectl create deployment nginxdemos --image=nginxdemos/hello
    
  5. To check the status of our deployment, run the following command:
    kubectl get deployment nginxdemos
    
    the output show appear as follows on complete.
    NAME         READY   UP-TO-DATE   AVAILABLE   AGE
    nginxdemos   1/1     1            1           23h
    
  6. Now to expose our application, we will Run the following command to expose this application:
    kubectl expose deployment nginxdemos --type=NodePort --port=8080 --target-port=80 --name=nginxdemos
    
  7. Open the Kubernetes dashboard.

    Note: Refer to the section Connect to the Kubernetes dashboard

  8. In the top navigation, select the + button.
    Plus
  9. Paste in the code below to create an Ingress to make your application accessible on the web.

    Note: On the host: line notice the special hostname {External-IP}.nip.io with an added prefix.

     apiVersion: networking.k8s.io/v1
     kind: Ingress
     metadata:
       name: nginxdemos-ingress
     spec:
       rules:
         - host: nginxdemos.169.169.169.169.nip.io
           http:
             paths:
             - path: /
               pathType: Prefix
               backend:
                 service:
                   name: nginxdemos
                   port:
                     number: 8080
    
    your browser should appear as shown:
    Plus
  10. Click Upload.
  11. In the left navigation select Ingress.
    Ingress
  12. The table shows the new ingress and assigned Host to access the application.
    Ingress table
  13. In a new browser tab or window, open the high-lighted endpoint from step 12.
    http://nginxdemos.169.169.169.169.nip.io
    
    Example:
    NginxDemos