Con­tainer Orches­tra­tion with Ku­ber­netes

OpenSource For You - - Contents - By: Vineet Ra­jula and Prof B. Thangaraju The au­thors are as­so­ci­ated with the Open Source Tech­nol­ogy Lab, In­ter­na­tional In­sti­tute of In­for­ma­tion Tech­nol­ogy, Ben­galuru.

Ku­ber­netes is a pro­duc­tion-grade open source con­tainer orches­tra­tion tool. It au­to­mates the de­ploy­ment, scal­ing and man­age­ment of con­tainer­ised ap­pli­ca­tions. Along with Ku­ber­netes, this ar­ti­cle will help you get ac­quainted with its pack­age man­ager, Helm—its charts will help you in­stall and even up­grade com­plex Ku­ber­netes ap­pli­ca­tions.

Did you know that with the ap­pro­pri­ate set­tings, you can run more than 1000 light­weight vir­tual ma­chines on your desk­top com­puter? You don’t need high­end servers to run such a large num­ber of con­tain­ers. Also, man­ag­ing all the con­tain­ers man­u­ally is a cum­ber­some task. To ease this task, we can use open source tools like Docker Swarm, Mesos, CoreOS Fleet, etc.

An in­tro­duc­tion to Ku­ber­netes

The use of con­tain­ers in­creased tremen­dously with the ad­vent of the Docker tool. For a large scale sin­gle ap­pli­ca­tion such as an on­line shop­ping sys­tem, mul­ti­ple con­tain­ers are used to achieve high avail­abil­ity, con­tin­u­ous de­ploy­ment, failover mech­a­nisms, high per­for­mance, etc. In such cases, the num­ber of con­tain­ers de­ployed is huge, and de­pends on the re­quire­ments. Some­times the con­tain­ers are de­ployed on mul­ti­ple hosts. Since all these con­tain­ers and hosts needed to be man­aged, the con­cept of ‘orches­tra­tion of con­tain­ers’ came about.

Ku­ber­netes is the lat­est buzz word in the world of or­ches­trat­ing con­tain­ers. It is an open source con­tainer orches­tra­tion tool with a great set of fea­tures. Ku­ber­netes is widely used amongst other con­tainer orches­tra­tion tools.

This ar­ti­cle guides read­ers on how to set up a Ku­ber­netes clus­ter us­ing Minikube in an Ubuntu sys­tem. There are many ways to in­stall a Ku­ber­netes clus­ter, de­pend­ing on the in­fra­struc­ture be­ing used. Us­ing Minikube is one of the straight­for­ward meth­ods. Minikube ab­stracts lots of in­ter­nals such as ini­tial­is­ing the core pods, pod net­work­ing and ex­pos­ing ser­vices, and makes it easy to fire up a Ku­ber­netes clus­ter.

So let us set up and run a Ku­ber­netes clus­ter lo­cally with Minikube and then ex­plore how to de­ploy ap­pli­ca­tions on to

the clus­ter, us­ing the Ku­ber­netes pack­age man­ager called Helm.

Ku­ber­netes in­ter­nals

Ku­ber­netes has been cre­ated by

Google, based on its ex­pe­ri­ence in run­ning huge work­loads. It is de­signed to work in dif­fer­ent en­vi­ron­ments such as vir­tual ma­chines, on bare metal sys­tems or on the cloud. It is com­pletely open source and is widely used these days. It is very mod­u­lar and can be cus­tomised up to the core. It of­fers mul­ti­ple op­tions for set­ting up the clus­ter, right from net­work­ing to con­tainer run­times.

There are some im­por­tant com­po­nents of Ku­ber­netes that we need to un­der­stand be­fore jump­ing into the in­stal­la­tion process. Fig­ure 2 shows a typ­i­cal Ku­ber­netes clus­ter, with mas­ter nodes and slaves (sim­ply called nodes). The mas­ter node takes care of the slaves and the de­ploy­ment of the var­i­ous com­po­nents of Ku­ber­netes in each of them. The mas­ter node uses etcd to store the in­for­ma­tion about what is to be de­ployed at what point in time in each of the slaves, and hence main­tains the state of the clus­ter. A clus­ter can be formed us­ing more than one sys­tem, which is why the com­po­nents are pack­aged into nodes.

De­tails of some other im­por­tant com­po­nents of a Ku­ber­netes clus­ter are given below.

Pods: A group of con­tain­ers on the same host is called a pod, and all the con­tain­ers in a pod share the same net­work set­tings such as the In­ter­net Pro­to­col (IP) ad­dress.

Clus­ter: A clus­ter is a set of nodes whose re­sources are used to run a set of ap­pli­ca­tions.

Ser­vices: The ser­vices pro­vided are load bal­ancers for the pods in a clus­ter, ex­pos­ing them to the out­side world. Repli­ca­tion con­troller: This con­trols the num­ber of repli­cas of each pod in a clus­ter, and also makes sure the num­ber of pods is equal to the replica count set in the con­fig­u­ra­tion. La­bels: La­bels are tags used to dif­fer­en­ti­ate pods, ser­vices and other com­po­nents.

Names­paces: Names­paces help in man­ag­ing pods in en­vi­ron­ments where de­vel­op­ers are spread across mul­ti­ple projects. They di­vide clus­ter re­sources be­tween mul­ti­ple users. Names­paces can be skipped in clus­ters with less than ten users.

Set­ting up a Ku­ber­netes clus­ter us­ing Minikube

Minikube, which is a part of the of­fi­cial Ku­ber­netes project, is a com­mand line tool to in­stall and run Ku­ber­netes clus­ters lo­cally. The clus­ter can be started or stopped, just like any other ser­vice in Linux. Minikube runs all the com­po­nents of the clus­ter like the nodes, pods, etc, in a vir­tual ma­chine on the host. There­fore, it is re­quired to ei­ther have Vir­tu­alBox or Ker­nel Vir­tual Ma­chine (kvm) in­stalled on the host sys­tem. Minikube, how­ever, can only run a sin­gle node clus­ter.

In­stalling Minikube

Run the com­mands as shown in Fig­ure 4.

The curl com­mand first checks if the lo­ca­tion is cor­rect or needs to be redi­rected us­ing the L flag. It then down­loads the lat­est ver­sion of Minikube and saves the out­put to a file in­stead of std­out, us­ing the o flag. The && com­mand is used to run mul­ti­ple com­mands se­quen­tially, one af­ter the other but as a sin­gle com­mand. The chmod com­mand gives ap­pro­pri­ate per­mis­sions to the down­loaded file, and the last com­mand moves it into the /usr/lo­cal/bin folder so that it can run from any di­rec­tory since the PATH is set by de­fault.

How to talk to the clus­ter

In­stall Kubectl, which is a com­mand line tool, to talk to the clus­ter and get the nec­es­sary in­for­ma­tion about it. It is like a medium of com­mu­ni­ca­tion be­tween the user and the clus­ter. Kubectl can be used to start, mod­ify or delete parts of the clus­ter. More de­tails on Kubectl can be found at https:// ku­ber­netes.io/docs/setup/pick-right-so­lu­tion/. To in­stall Kubectl, run the com­mands as shown in Fig­ure 5.

Sim­i­lar to the Minikube in­stal­la­tion, these com­mands down­load the bi­nary file of Kubectl, give it ap­pro­pri­ate per­mis­sions and move it to /usr/lo­cal/bin. The in­ner curl com­mand ex­tracts the lat­est ver­sion num­ber.

Start­ing Minikube

Run the fol­low­ing com­mand from a ter­mi­nal: $minikube start

In no time, the clus­ter will be fired up and run­ning. To check if Kubectl and Minikube are in­stalled prop­erly, run the com­mands as shown in Fig­ure 6.

The out­put is a ta­ble with six col­umns. The first col­umn in­di­cates the names­pace to which a pod be­longs. The sec­ond col­umn in­di­cates the name of the pod. The third col­umn shows the num­ber of pods to be sched­uled and the num­ber of cur­rently run­ning pods. The fourth col­umn shows the sta­tus of the pod. The fifth col­umn shows the num­ber of times the given pod has restarted. The last col­umn shows the age of the pod, i.e., the time since the cre­ation of the pod.

Now we have a Ku­ber­netes clus­ter run­ning lo­cally. As you can see, we didn’t have to con­fig­ure the net­work or any other re­source specif­i­cally. Minikube takes care of all the in­ter­nal con­fig­u­ra­tions. Hence, Minikube saves a lot of time when de­ploy­ing ap­pli­ca­tions in a de­vel­op­ment en­vi­ron­ment lo­cally.

Stop­ping a clus­ter

Some­times we may have to stop the clus­ter to free com­put­ing re­sources. In such a sce­nario, run the fol­low­ing com­mand:

$minikube stop

Now that we have set up a clus­ter, let us in­ves­ti­gate Helm, with which we can de­ploy ap­pli­ca­tions like Word­Press or MySQL on the clus­ter, with just a sin­gle com­mand.

Us­ing Helm

Helm is a pack­age man­ager for Ku­ber­netes that stream­lines the process of in­stalling and man­ag­ing ap­pli­ca­tions on the clus­ter. You can re­late to it as apt/ ebuild/ yum/ home­brew for Ku­ber­netes. The name ‘Helm’ refers to the steer­ing wheel of a ship. In the con­text of Ku­ber­netes, in­stead of steer­ing a ship, Helm steers the clus­ter, hence man­ag­ing ap­pli­ca­tions as il­lus­trated in Fig­ure 7.

Helm ap­pli­ca­tions are writ­ten as Helm charts, which help us de­fine, in­stall and up­grade any Ku­ber­netes ap­pli­ca­tion. Charts are gen­er­ally pre­con­fig­ured Ku­ber­netes re­sources.

Helm can be used for the fol­low­ing tasks: a. Man­age re­leases of ap­pli­ca­tions b. Share ap­pli­ca­tions as charts c. Man­age Ku­ber­netes man­i­fest files d. Search and use al­ready ex­ist­ing ap­pli­ca­tions pack­aged as charts

Helm com­prises two parts—Helm (a client) and Tiller (a server), as shown in Fig­ure 8. Tiller runs in­side Ku­ber­netes and man­ages the in­stal­la­tion of Ku­ber­netes charts. Helm can be in­stalled on lap­tops, servers, or on con­tin­u­ous in­te­gra­tion or con­tin­u­ous de­liv­ery tools like Jenk­ins or Chef.

Ku­ber­netes charts can be stored on a disk or they can be fetched from re­mote repos­i­to­ries. A chart con­sists of two im­por­tant things: Chart.yml (de­scrip­tion of the chart) and one or more tem­plates con­tain­ing Ku­ber­netes man­i­fest files.

To use Helm in a se­cure and ef­fi­cient way, you need a Ku­ber­netes clus­ter, Helm and Tiller con­fig­u­ra­tion. You need to de­cide what se­cu­rity con­fig­u­ra­tions to ap­ply to your in­stal­la­tion such as con­trol­ling the clus­ter in net­work en­vi­ron­ments, mul­ti­tenant clus­ters, clus­ters with ac­cess to im­por­tant data, etc. More in­for­ma­tion on se­cur­ing Helm can be found at https://docs. helm.sh/us­ing_helm/#se­cur­ing-your-helm-in­stal­la­tion/.

De­ploy­ing ap­pli­ca­tions us­ing Helm

First, we need to in­stall Helm in or­der to be able to de­ploy ap­pli­ca­tions with it. To in­stall Helm, run the com­mand shown in Fig­ure 9.

These com­mands will down­load the Helm script and save it as the get_helm.sh file, then the re­quired per­mis­sions are given, and the script in­stalls Helm.

To start Helm, ex­e­cute the fol­low­ing com­mand: $helm init

This will cre­ate a server as a pod and con­fig­ure the clus­ter to run Helm. There are many ap­pli­ca­tions that can be in­stalled us­ing Helm. An ex­haus­tive list of Helm-sup­ported ap­pli­ca­tions can be found at Kubeapps Hub [6].

Let us in­stall the Ku­ber­netes dash­board by run­ning the com­mands shown in Fig­ure 10.

This will in­stall the dash­board ap­pli­ca­tion as a pod on the Ku­ber­netes clus­ter. Af­ter a while, run­ning the com­mand from Fig­ure 6, you will see a pod run­ning with the name ‘osfy-sm­ple-app-ku­ber­netes-dash­board-xxxxx-xx’. The last few char­ac­ters are ran­domly as­signed by the clus­ter it­self.

Once the pod is run­ning, ex­e­cute the com­mands as shown in Fig­ure 11 to ac­cess the ap­pli­ca­tion. These com­mands are needed to ex­pose the port of the dash­board to your host, so as to ac­cess the ap­pli­ca­tion from your host.

Af­ter a few sec­onds, open the URL http://lo­cal­host:9090 in your browser. You will find the dash­board of your Ku­ber­netes clus­ter as shown in Fig­ure 12. The dash­board has three fig­ures on the top, which in­di­cate the run­ning sta­tus of all the de­ploy­ments, pods and replica sets in the clus­ter. The other things on the dash­board are self-ex­plana­tory.

Some­times, we may want to delete the ap­pli­ca­tions de­ployed for var­i­ous rea­sons. To do so, run the fol­low­ing com­mand:

$helm delete osfy-sm­ple-app

As you have seen, it is easy to run a Ku­ber­netes clus­ter lo­cally, and Helm makes it sim­ple to de­ploy ap­pli­ca­tions on the clus­ter. Helm charts make it eas­ier for any­one to pack­age their ap­pli­ca­tions and de­ploy them on the clus­ter. In this ar­ti­cle, we have only dis­cussed de­ploy­ing ap­pli­ca­tions, but once that is done, in a later ar­ti­cle we can look into the fea­tures of Ku­ber­netes—like self-heal­ing, replica-sets, scal­ing the pods, state­ful sets, cus­tom re­source def­i­ni­tions, etc.

Ref­er­ences

[1] Borg, Omega and Ku­ber­netes–ACM Queue-https://queue. acm.org/de­tail.cfm?id=2898444/ [2] Ku­ber­netes, pro­duc­tion-grade con­tainer orches­tra­tion https://ku­ber­netes.io/ [3] Pick­ing the right so­lu­tion-Ku ber­nete s-https://kub er net es. io/ docs/ setup/ pick-right-so­lu­tion/ [4] Over­view of kubectl-https://ku­ber­netes.io/docs/ref­er­ence/ kubectl/over­view/ [5] Us­ing Helm-https://docs.helm.sh/us­ing_helm/#se­cur­ingy­our-helm-in­stal­la­tion/ [6] KubeApps Hub: Dis­cover and launch great Ku­ber­netes­ready apps-https://hub.kubeapps.com/ [7] Helm docs-https://docs.helm.sh/

Fig­ure 1: Minikube logo (Source: https:// github.com/ku­ber­netes/minikube/)

Fig­ure 2: The in­ter­nal struc­ture of Ku­ber­netes

Fig­ure 4: Minikube in­stal­la­tion com­mands

Fig­ure 5: Kubectl in­stal­la­tion com­mands

Fig­ure 7: Il­lus­trat­ing how Helm is used (Logo sources: Re­spec­tive web­sites)

Fig­ure 8: Helm ar­chi­tec­ture

Fig­ure 6: Get the list of the run­ning pods

Fig­ure 12: Ku­ber­netes dash­board ap­pli­ca­tion

Fig­ure 10: De­ploy­ing ap­pli­ca­tions on Helm

Fig­ure 9: In­stalling Helm

Fig­ure 11: Run­ning the dash­board ap­pli­ca­tion

Newspapers in English

Newspapers from India

© PressReader. All rights reserved.