This article discuss the steps to create a Kubernetes cluster and deploy a web application.
- An IBM Cloud account, to sign up visit this site.
- Log in to IBM Cloud.
- In the top navigation, select Catalog.
- Select the category Containers.
- Select Kubernetes Service.
- Under the Plan details section, select Free tier cluster.
- Click the Create button.
- 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.
- Once the cluster has been created, green checks will appear across the status tiles.
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.
-
In the top navigation, click the button with the Terminal icon. A new browser tab opens titled IBM Cloud Shell.
-
Back in our cluster Overview tab, select Actions > Connect via CLI.
-
In the Connect to CLI dialog, run the referenced 3 commands in the IBM Cloud Shell tab.
Example output:
- Under the top navigation, click the Kubernetes dashboard button.
- A new browser tab opens titled {cluster name} - Kubernetes dashboard.
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.
- 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
- To monitor progress, run the following command:
Example output:
kubectl get daemonset -n nginx-ingress
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE nginx-ingress 1 1 1 1 1 <none> 24h
- To determine the
External-IP
of the node, run the following command:Example output:kubectl get nodes -o jsonpath='{.items[0].status.addresses[?(@.type=="ExternalIP")].address}'
169.169.169.169
- That's it! When creating an ingress, be sure to use the following hostname format:
Example:
{External-IP}.nip.io
169.169.169.169.nip.io
In this exercise, you will create an application using the Docker image nginxdemos.
- Connect to the IBM Cloud Shell.
Note: Refer to the section Connect to the IBM Cloud Shell
- First let's create a new namespace. To do so, run the following command:
kubectl create ns callforcode
- Let's set
callforcode
as our default namespace. To do so, run the following command:kubectl config set-context --current --namespace=callforcode
- 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
- To check the status of our deployment, run the following command:
the output show appear as follows on complete.
kubectl get deployment nginxdemos
NAME READY UP-TO-DATE AVAILABLE AGE nginxdemos 1/1 1 1 23h
- 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
- Open the Kubernetes dashboard.
Note: Refer to the section Connect to the Kubernetes dashboard
- In the top navigation, select the
+
button. - 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.your browser should appear as shown: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
- Click Upload.
- In the left navigation select Ingress.
- The table shows the new ingress and assigned Host to access the application.
- In a new browser tab or window, open the high-lighted endpoint from step 12.
Example:
http://nginxdemos.169.169.169.169.nip.io