Kubernetes — Orchestration Guide [A Lovely Symphony 3]

Covenant Chukwudi
MyCloudSeries
Published in
4 min readApr 28, 2019
Kubernetes orchestration guide — image credits conainerjournal.

This is a part 3 of our on-going Kubernetes guide. We started with our part 1 here where we got introduced to the world of container orchestration and what Kubernetes has to offer. Then we moved into our second part of our learning and exploration of Kubernetes concepts where we went deeper into the concept of Objects, Pods and touched Services.

We will continue our discussion on understanding Kubernetes and getting into practicals.

If you have been following our series, you should have your Minikube Kubernetes environment setup. You should also have your Nodejs code-base setup with the ourapp-node.yaml(which describes our service) and ourapp.yaml(which describes our pod) file.

kubectl apply -f <path/to/file>

Kubernetes console tool (kubectl) provides a lot of commands which we would be using very frequently, one of which is the kubectl apply -f command.

We use this command when we want to communicate configuration changes/actions into our Kubernetes cluster.

The -f attribute is used to specify the file that contains the configuration we are trying to apply.

The <path/to/file> section as the name indicate is the filename containing the configuration changes/actions we want to load and apply into our Kubernetes cluster.

Head over to your command line in the root folder of your codebase and let’s load up our 2 config files into our Kubernetes Minikube cluster starting with ourapp.yaml file which contains our pod definition.

First start-up Minikube if you don’t have it running by using this command:

$ minikube start

Then run this command:

$ kubectl apply -f ourapp.yaml

You should see a response similar to this:

pod "ourapp-container" created

Next, we try to apply our service configuration which is in the ourapp-node.yaml file.

$ kubectl apply -f ourapp-node.yaml

You should see a response similar to this:

service "ourapp-node" created

If you didn’t encounter any error then congratulations! You have successfully applied both configuration files to your Kubernetes cluster.

If you encountered any errors, please feel free to let me know.

kubectl get

Now that we have “applied” our configurations successfully, an important command to get familiar with is the kubectl get <resource> command. This command enables us to retrieve information about running objects.

kubectl get po

Running the above command in your command-line, for example, gives you information about running pods in your Kubernetes cluster.

You should see your newly created pod “ourapp-container” in the list returned with the status of “RUNNING”.

$ kubectl get po
NAME READY STATUS RESTARTS AGE
hello-minikube-5857d96c67-s8mdg 1/1 Running 3 82d
ourapp-container 1/1 Running 0 32m

kubectl get services

To view services (kubernetes networking objects) like the one we created through our ourapp-node.yaml file, we simply use the object type services in conjuction with our kubectl get command.

To do this, in your terminal run:

$ kubectl get services

You should see something a bit similar to this

NAME             TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
hello-minikube NodePort 10.109.191.197 <none> 8080:32749/TCP 82d
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 82d
ourapp-node NodePort 10.106.63.17 <none> 5050:30001/TCP 31m

Most importantly is to see a service of the name “ourapp-node” which represents the service you created earlier-on.

Accessing your app

Now that we have successfully created the needed kubernetes objects from our config files and have successfully reviewed their status using the kubectl get command, the next thing is to try and access our app from the browser.

To access our app from the browser, we need to first get the IP address that was assigned to our kubernetes cluster Virtual machine by minikube,

To do that simply run:

$ minikube ip

Now, go to your browser and type in that IP together with our “nodePort” number we defined in our service (30001).

My own ```minikube ip``` was 192.168.99.104 so i head over to my browser and type 192.168.99.104:30001. You should get a success page like this:

successfully running our kubernetes app locally

Sticky Notes

  1. kubectl apply -f command enables Kubernetes to accept and implement configurations in our declarative config files telling it needs we have.
  2. Declarative configuration styles are much more preferable than Imperative configuration styles.
  3. You can use the kubectl apply -f command to create any type of configuration for most Kubernetes objects such as Pods and Services.
  4. kubectl get command enables you see the status of running resources in Kubernetes. For example, the running kubectl get po helps you see the list of all running pods in a cluster.
  5. You can access your locally running kubernetes app by using the IP address of the minikube vm running on your system which can be retrieved by running: minikube ip.

Conclusion

Kubernetes is a really awesome technology and we are just beginning to experience what we can achieve with it. It still has a lot of parts which we are going to explore.

--

--

Covenant Chukwudi
MyCloudSeries

I build products that would have positive effect on lives