How to deploy your first pod on a CentOS Kubernetes cluster

Автор: | 13.06.2018

So you now have your Kubernetes cluster up and running on your CentOS 7 servers (see: How to install a Kubernetes cluster on CentOS 7). What next? Easy. The next step in the process is deploying your first pod. What is a pod? Simple. A Kubernetes pod is a group of one or more containers that share storage, network, and the necessary specification for how to run containers. A pod’s contents are always co-located, co-scheduled, and run in a shared context. A pod allows you to specify the containers to be run and then Kubernetes automates setting up the proper namespaces and cgroups.

A simple way to think of a pod is it is the means to deploy a container in a desired state. For example: You deploy a pod of containers and the desired state of the containers is to be running. However, upon deployment, the containers (for whatever reason) fail to run, the pod will continue to re-create itself in an attempt to get the containers at the desired state.

With all that said, let’s deploy a pod on our CentOS 7 Kubernetes cluster. If you followed the first tutorial, you should have everything necessary to take care of this.

Creating our pod

As has become tradition (for those covering containers and the like), we’re going to deploy an NGINX pod to the cluster. You’ll be surprised at how easy it is (because we’ve taken care of the challenging part already).

The first thing you’re going to do is log into kubemaster (remember our naming scheme from the original article: kubemaster, kube2, kube3). Once logged in, create the deployment with the command:

sudo kubectl create deployment nginx --image=nginx

The output of the command should indicate the deployment was created (Figure A).

Figure A

Figure A

Our deployment was successful.

If you want to see the details of the deployment, issue the command:

sudo kubectl describe deployment nginx

You should see output similar to that in Figure B.

Figure B

Figure B

The details of our NGINX deployment.

Our next step is to expose our newly-created NGINX pod to the internet. I will assume you want to expose internal port 80 to external port 80. For that, issue the command:

sudo kubectl create service nodeport nginx --tcp=80:80

You should see service «nginx» created.

With no errors reported, you can then check the status of both the pods and the service with the two commands:

sudo kubectl get pods
sudo kubectl get svc

You should see that both pod and service are both ready (Figure C).

Figure C

Figure C

Our pod and service are up and running.

According to the output above, the NGINX pod is running under the cluster IP address 10.111.196.152 on port 80 and the node main IP addresses (in our case 192.168.1.109 for kube2 and 192.168.1.167 on kube3) at port 30778). To test out the pod, issue the command:

curl kube3:30778

You should see the HTML contents of the NGINX welcome page (Figure D).

Figure D

Figure D

Our pod is up and running.

If you point a browser to http://192.168.1.167:30778, the NGINX welcome page should appear.

Congratulations

You’ve deployed your fist pod on a Kubernetes cluster. Wasn’t so hard, after all, was it? For more information on Kubernetes (and how to make your cluster do really impressive things), check out the official documentation. And, of course, check back on TechRepublic for more Kubernetes tutorials.

Also see

Source

Добавить комментарий