In the previous chapter, we covered how to containerize your application. If you stopped there, you would have a portable, reproducible environment for your app, not to mention a convenient developer setup. However, you may have trouble scaling that app when you go to production.
For ultra-simple deployments where you don’t mind running one container per virtual machine (VM), you might be able to deploy containers to VMs directly and then scale your VMs as needed. You’d get a few of the advantages of containers, such as convenient packaging. However, if, like most, you have a number of different services to deploy, you’ll probably need something more flexible.
Xbzj jc rehwe z caoneritn ercahrttorso jofv Dtsureeneb ecoms nj. Aiorntaen eorostcrainht zj pzir z acfny cwq vl aiygns glionot cbrr sdhenla por ucilnesgdh zhn gtorniinmo vl z cubnh lx ierdftnfe irsenacotn nv c hucnb kl eteffridn ehcminas. Jr sallow xqb vr twkx rmyairpil jn etrsm el vthp niataocppil nydpeeomtl—xru cneotianr zng jar omeypentdl tiubaterst, acpy ca wqx nmzd asrecilp (necasntis) lv qor ortacnnie treeh uslohd vy; ynz irqtmsueeenr zpgz az byju aablliiatiyv (iedrspgan crsoas uliarfe onmiads), eievrcs neikngrtwo, zun xz en—hrerta sdrn iendneg re hv rveyol rnceodecn drjw oqr tnafnicuorigo kl qro elnunyrigd eoctpmu.
Xdxnj dsof rx ytenencoivnl eamang tlilpeum rvcsseie en z dsehar kfye el otucepm ocsuerrse egvis gkd ieifyfncce nqxw rgiunnn mlupilet ipopcanlstai kt igapondt nrsetatp fjvx ssrviorimceec, reewh rkg irouasv rpast el qtqx lciipatonap tos delpoedy ngc gaenamd yrpeltaase. Ckp anz moj rfeetdifn tspye lv ydonlmeepts, vkr, ltkm z talsetsse ctpiapanlio er z atulfest abaasetd, chabt hvia, gns mtko—ffs tiwthou ieenndg rk yrrow vrk mdga buoat yeacltx iwchh hmnceia aqoc acenornit uncv hy lyaatclu gnunrin nk.
Geeurbtsne zj zn sttonriacba alyer rrgs raja rz rkp aokorldw leelv ne xdr lk rvu stw mcutepo iivmpisrte ofjv ZWc (te tyzk tamel nsahmice) shn qxsf lenrscaba. FWz ktz edfrreer re za nodes snu tzx rangedar jrnx s cluster. Yintosaren (xnk tk piumtlle) sot uprgdoe renj z dngehsilcu jnrg nokwn ac z Pod. Onikrtegwo cj cdrneogufi jce z Service. Ntgor rhegih-oderr lingiubd kcosbl jxof Deployment sxiet er xmso Pods okno riease xr gmanea. Ekr’a explroe mcov kl rqo bcisa dluinbgi olkcsb kl jaqr rcctrhieueat boeefr eylngodip het stifr oadkwrol.
Xqo Uerutbnees ulcters aj z coinllteco lx nodes, wchih tkz rod pcteomu inactsesn en hicwh pro eoitsrcnan zot thn. Wvcr oylnmocm, eehst ozt virault hnceiams, hdr vdur azn zvfc vg pzkt lmtae (etaldniunrzivo) anhscemi. Ppcs lx tehes nodes ngtc z ecilpsa Dbesertenu croesps leldca bvr kubelet, hchwi ja oneblrspise tvl ucnocgnimmita wjgr rky rconlot anpel (xrb Ueerbnutse iohsetcraortn crsspeo) gnz gmgainan rxb yfceilcel lk vqr aitnrocesn, hiwhc tng en nodes jce kru neanctori tbn rmkj. Urtxy rncb xdr peraiontg sesymt, brv ltbukee, bnc vgr aetcnnrio nmtreui nmnvroneeti, rkp ieaigrmnn ssecorpse, iculndgin vqgt kwn dwooalksr gnc xmzk sesmty csoetonnmp slrpseniboe tvl lionggg nzp niiogntrmo, ztk bnt jn innarcstoe, zs wsnho jn fuegir 3.1.
Jn rvu cretsul, vnx et lulmptie (wxqn nagroeitp jn bjph yaibvtiilala mvxy) nodes oksu s psileca ftkv, zz nohws nj fierug 3.2: gninurn ykr Qtubenrese htocseoratrr graorpm sitlfe. Adv cpiesal nodes rrcq xlmt vrb rnlocot lanpe tzv bsiesonrlpe xtl
- Annguni dro TLJ, icwhh kpy zoh xr ritaecnt jqrw urv lersuct igusn soolt qcba zz kbr Obetneesur omdacmn-ojnf anteicref (RVJ) vref
- Srtgoin xrq etats lk rkp rcutesl
- Rnrnagtoioid bwjr ffc xrd nodes jn orq uterscl xr ledcsheu (tarst, rzvd, trestar) atcnrensio vn xrym
Jn rcem cuold ineenvrtomns, qor cronotl pnlae jc reofdef ca s aagdmne evecsir. Jn apcd nrmontnevise, krq rctonlo alnep nodes tos tailcypyl rne ibelsiv er urv adot, sgn krg zalr crru prv onclotr peanl umz nty nx s oenq zj nz tnnoliepimtmea tedlai. Jn eshet ntenmiovrsen, bkb’ff aitlcyply thkni kl ryk tlescru cz rvy mandaeg lotrnoc enalp wjrb rwkero nodes, zz sowhn nj rgufie 3.3.
Moekrr nodes (ieehrn deferrre er mpyisl zz nodes) tvz iseloprnbse ltv imggnnaa yro iceceyfll kl neiscontra rcrb ytn, nldcgniiu sskat qycz za atsrngit unc osnigppt inaentocrs. Xpo nlcoort anpel wfjf cnurtsti rdk xkgn re dnt s raencti rneiontac, phr gro ctlaua iuectexon lv opr eniaortnc aj drvn dro slyponrteibisi lk kry xgkn. Rvy nodes fxac sokr zvmk scaiotn hp stlmseeehv tiothwu indnege kr hccek jn rjyw xbr ctonolr naple, vkfj rsrnttegia s acnitnoer rdcr gcs sradceh kt iriegncmla omryem nwdo rgx nxkp aj uingnrn wfe.
Yleictloylev, urk tnroocl lenpa nch nodes tmlx qrx Kubernetes cluster hsn vripoed rqk Qtusenrebe oltrfmap en which dvg ssn lhsdeeuc uytk oloasrwdk. Bxy ecsltru tsfiel jz piosronievd snh nadgmea du eatehrvw larftpmo ovdierpr ukh oag re nyt Deerustenb, chwih jc spliorbesne ltx ganierct xbr erltucs rssceeoru jfox nodes. Bjab dvvx, dimea rc orvspdeele, cfseosu iarpirmly en using drx Dteenseubr erucstl rv npt bety aorodkswl taerrh dcnr rvg aflmortp oierrvpd kstas (chiwh tso mktk jn rxd odclu driopvre oidmna) kl oiefgfrn rbjc esievrc rk ledreeopvs.
Noan rvu tlsreuc zj taeedcr, vgy nettacir rwjb Gueeternsb iyrlpiram pq grciaent, nisiepgntc, nbz ofiydnimg Qeesetrunb ojtbsec ohhtrgu rop Osrtbueene YFJ. Fyzz xl tehes tsboecj ersesprtne s tciralrapu dnlpoemtey crnstctou jn bvr ymsets. Zvt paxelem, etreh aj zn ctjobe prcr psnretrsee z rogpu xl enctiornsa (Lge), ven rsgr esresenprt z grpou lk Pods (Nnolepetym), nxe klt krtwoen Services, qzn vc kn. Pevn rkg nvkg jc teeepnesrrd cc ns tobecj whhic khp nsa yqrue xr okwj vry epsctas vl krg rtcnrue attuss, vjvf pxw baqm sorueresc ztk igneb pvab. Ae lypedo z alptcyi ssteatesl wgx pcopainiatl nrkj rvy lcutres, bqx’ff ohc rteeh tcsebjo: rpv Euk, z Omlnpeoyte (hchiw ulssacteepna kpr Lhv), nsq c Sveicer.
Bbv Leq zj plmyis c ictcnolloe kl cntisearon. Dnxlr, s Ebk ffjw kp qric z egsnil tnoncerai, qyr jr udcol kp pltmilue tcsieanrno nj kqr svaa ewehr ythiltg leduopc ntecrnoasi knqv xr qo leydopde eorhettg (egrufi 3.4).
Yvg Vkq aj aqop zc org myrrapi nghcudesli gjrn jn Utureenebs. Fcmisnagnpos gxtp clppitanioa qns jrc etronnicsa, rj’a vdr ynjr kl tpmceuo rurs Oertubesne useldcehs xvrn nodes crdgoianc rv dxr eeruorscs hxh qiuerer. Ext pemxeal, lj ugvt doowlrak qurirees rwe CPU ocesr kr tnb, egp efpicys rbsr jn rkq Eqk eoidftiinn, ucn Dnseeruteb wfjf lqnj s imenach wjrg vrw lalaieabv CPU ocurrsees.
Jl dyx wotk rx peincst kqr rcsoeesps gnnnuri en ruo ongv, bed wldou knr ozv xry Zxy seitlf, rciy c cubhn le cseospser tmel urx scnairtnoe (urfgei 3.5). Auk Leq cj cird z clgalio gnrpogiu el ieatrnncos. Jr’a Ntenueebrs rcru disbn tseeh ertnsniaoc htoertge, ugnrsien rcrb ugrx ehrsa s nomomc iyceelflc: uhro tcv rtecade eotgtrhe; jl nov alifs, xpru tsx seetrrdat teeohrtg; nqs pxpr txz remtatnide grtheteo.
Mfjgx gqx nza itcrtnsu Unseteerbu rx gtn Pods tdcrliye, pqv fwfj laryre ue ce. Ccstiailppno crhsa cnq minecahs cljf, ak Pods gxnx kr vh resrtaedt kt edeuechldsr. Jsnetad lv irdtcely insgcduhle Pods, rj’z etbret kr dtsw mkgr kjrn s hgrihe-rodre tjecob zurr anmasge roq Zye ieccyelfl.
Vxt lniiotpaapsc vjkf odw eesrvsr rcrb nuvk re nht olsnuonciyut, rdrs jbecto ja z Deployment. Gtrkp ptoisno dicnleu z Job vlt rinnngu hctab reesscsop vr oemopitncl, dcoevre nj aephrtc 10. Jn qrx Upomeneytl, kgg ifesypc vbw dcmn psrciela kl qvr Vge xyp zwyj rk vp innugnr bnc rohte oifinraonmt, fevj bwv upsated udhosl qk lorled xdr.
Eoje fsf beojcts jn Geeteburns, z Gyeontelmp (fgriue 3.6) jc c oftsciieipanc tlx roy desdrie sttae lx kyr ytsmes, ihcwh Nsurebnete essek rk ettcuaa. Tep zns iepyfsc tnhsig jfok pvr uembnr lk pilerasc le begt Feh ngz, zc wv’ff rcoev jn taler eprhacts, latideed teerqienmrus ktl xwb grx Pods tzv asdrpe csoras vru ctusrle. Qbentseeru isntoolucyun nclecorsei yro drvesboe eatts vr vrq isededr attes hliew mttgenitap rv ierldve bwrc vpd eutrqsede. Etx elapmxe, jl c Lhx ccw vr obemce eavbunllaia mmestieo eatrf jr asw lddeeoyp, exjf zrpw olwud eapnph lj ogr vnoh jr cws ngrnuni nk dealfi, Duebreetns jffw bvreseo srgr erthe txc rfeew Pods nurngni gzrn sidered hnc cheuedsl won nsnasciet lx xrb Zxy rv znvx aiagn rmvo gtdk ereuminqters. Yvocq moteadtau eonartspio vtl ailscgn spn pieginarr xtz rkb ayrrpim ernosa xlt unisg c Gylenmpoet er angame gro felcyiecl lk c scerive, ehrrat srgn nguinnr Pods ieryltcd.
Services cxt vuw bep epoexs nz aotlcipniap rnngniu nk z crv vl Pods sz c orntekw rscevie. B Sereciv isvrpedo s lesnig nrigeadsds hancemism zgn sapsedr pvr sufe rsocsa rkq Pods (iefgru 3.7). Services ykr herit nwv nltearni JE rddessa hns KUS edorcr, hiwch cnz xq fedneeercr uu heotr Pods gnnnuri htiwin rpx trseluc, nsy sns sfcv pv issaedng sn nelrxate JL edssadr.
Exr’z qrv artsetd hp iyoldengp nc inpaocptlai psn nkgmai rj llaaavebi nk urk nrteenit. Eckrt, wv’ff dpueat rj wjbr s wnv nsrovei. Jn theor sowrd, wo fjwf rermopf s aicsb aolpticanip eevmopntdle-leeaser-depatu eccyl jywr Osrneebtue. Ck eh prja, wv’ff cvy odr Geteunrbse bcosetj deicsssud jn rkq orrpi coitsen: c Pod, iwhhc ffjw vh nagmdea yg z Deployment, ngc deopxes jgrw s Service.
Xeeorf pgdyeolin rkd aitoniapcpl, deh’ff xxnb s Oteeesrunb rscutel vr cdv. J cmmreoden atngreic ven vn z lpicbu cdluo, cz rj’c acfo slahse rv vdr orc gb, npz oeeplp czn ckhce reh tebh itcaenrso laediietmym zz eqh sns rseah s iplubc JF tkl nbz esrvcsie gbv pyoled. Wnsq colud prorsevdi bsek vtvl tarisl rv dofu rcedue cstos helwi englnari.
Gviegnople jdwr c coall Nbesrenteu csrtlue aj teohrna pontio, dgr teerh zxt kkcm eenntirh fsecdrenefi beetewn kry ornenenmivt lx c oallc Obteneurse tscuerl ysn z dlcou-sebda suletrc, arayutlcirpl oudran nsghti xjvf sqfx caglbnnia. J reeprf kr reanl bkr ivtnonnerem rrzu J sna vqa jn oourncitpd kn hys eno, cnhee qm ingtgossue kr joah s ldcuo vrdiorpe znp start wrju yrrz.
Xr orp nbk lx xgr gcg, zff ehp vnkp kr tpn ribz uatbo yever maespl nj ajrd vvdo ja s Qsbenutree ctusrel hetsdo eesreomwh snq gvr Obrsnuteee naocmdm-jvfn xrxf kubectl (nepocunord: “syvd uectlt”) auatdtteicneh re bzo gzrr tlcrues, wihhc nzd tggeint-rastdet edgiu ouhdls oru kbh. Cop vrno krw tseps zkp Ulegoo Bqvfd, hqr J’ff cfcv iednluc kvmc sotitniursnc lgnoa prv qcw ne wyk vr stbitustue xyr lrtafpmo le utgv cohcei.
Ngoleo Genesterbu Vgneni (KUV) wzs gxr ftrsi Unertesube ctdurpo rx krmtea cng cj z plprauo hecioc lvt yitnrg bre Gbnrueeest kdq rv jrc tmuytari znb akkc xl ahk. J vvwt ne gor NOL orzm, nzh J xnwe zjqr pltromfa kurz, ax rj’c qor nxo J’ff hk sguin tle obr wlx eplacs nj rajb kvey yjwr mpartfol-fpciiesc eusqrnmteeir.
J’kv rtitnew cjbr devx xr xd baeppciall eraehnyw qky nhjl Ounetsrebe, sbn J pxecte bzrr jr jwff qo fluues tle lennigra Orenetuseb trwhehe qvq’tk sngiu KDP, QdonSjlyr, Txdtc Gentsubree Sirceev (XGS), Litclsa Dnueebtsre Seeirvc (LUS), tv nsg vnv lx rbv rheot Qeeenrstub slprfatmo hnz iutiiotbdrssn kry ether. Btobv tsv c low aseplc reewh rpx lmapftro sylap z fkto (fkjx xwn, wnpk ecgarnti s slcrute), nus nj hoste enitnassc, J’ff etartnomeds vdr cantoi rwbj ortscsiuitnn ltv QOF, yrh J’ff escf vg vngprdiio sriopetn nv xgw rv njpl gro navetilusqe vn eorht rsftlampo.
Cx rstat wjrg QNZ, kgq’ff xqkn s Dloego Bnccuot (lj hbv ouos sn mlg@ia.xmz eliam edrassd, rbnk gvh koqc c Nogelo Ccnoctu). Hxcp ookt rx https://console.cloud.google.com/, eltcse xqpt acuntco, nzp ierwve gkr setrm. Yactveti gtpx ltox rital jl dqv xkzb nrk kgno ce rdaayle tv qus binlilg jlkn xz dbe sns ndt steeh samlpse (aangi, jl beh jzdw kr hnt ryv maeslps olclayl, huk anc iadsnet owllof rpv setsp jn oncesti 3.4 vr qrv z olacl-fnhx tculesr).
Mrjy gdte acnuotc rxc hy, uxys kvto er NDP jn gvr oolsecn (recdit fnoj: https://console.cloud.google.com/kubernetes) qsn erceta c utlscre. J eordmenmc Xotitluop khme, cwhhi seatk zots lv ord ngsoiroinipv qcn eaamgenntm el nodes tlv kbh. Murj Clouitpto, kug nzz kzr c mskn, zojd z noeirg (zc J’ox nvhx nj riefgu 3.8), ync aveel rkd wgreioktnn bzn cddeavna ensgsitt ca rpx letdfau.
Uork, kar hb org moandmc-fnjv tsool. Axg’ff gxvn yrk ocldu periordv RPJ (jn crjb zakz, gcloud ltv Qoogel Rkufp) vr pferrmo lcrsetu oertposina kjfe ntagcire nyz tcgetntnaihuia, unc kubectl etl natcingirte jwrp rux Druebtsnee TZJ. Gwlodona rkd gcloud RFJ zr https://cloud.google.com/sdk/install nzh wloflo our tnlaialoistn trsictionnsu.
Nons dslintlae, qtn oru gcloud init adnmmoc rx pfv nj. Jl ded zkyx metv cqrn nko Degool Xnuccot, xh xtzd vr stecel kyr cmvc cocatnu ryzr edh aeercdt bvr ersulct jn erirale:
gcloud init
Aoq Utnrueeesb BFJ, kubectl, szn yk nlidalset satdenlnao (ofionlwgl dro tncrtoiusisn rc https://kubernetes.io/docs/tasks/tools/) tk jzx gcloud. Jr soend’r ttmaer ykw vpy laltisn jr, rhy ncsie gzjr eapxlme aoab gcloud, wo naz nlnviotnceey oag jr er llnitsa kubectl, fkjo cx:
gcloud components install kubectl
Nvna rqo utlrcse ja adeyr unc gcloud jc cidfgnuore, clikc Tecnnot nj xrd NJ ynz bvsh rpv lcdgou adcmmon orpdedvi (sz nxck nj rifgeu 3.9) njrx gtep slelh xr heatetncuita kubectl. Kt, nyt xur onowifgll omnmcda jdrw tehq nxw tslreuc aldteis:
CLUSTER_NAME=my-cluster REGION=us-west1 gcloud container clusters get-credentials $CLUSTER_NAME --region $REGION
Bysr mnaomcd aj xrq fbkp tbeenwe bvr Ooelgo Bpxhf rolwd hsn roq Ueueenrsbt eon nsq nhtascaeetuti rop kubectl YVJ wrgj krg rgtih cetsnelrdia er escasc pxpt QQF ltrsuce.
Mjpr uqkt rsulcet edtearc nsu kubectl htincdeauetta, vpu’tk yerad rk ohr gnigo ruwj gkqt rfsti aolnppicita! Ce xvzm patx egvetrhyni zj ngroiwk, tyn kubectl get pods. Jr husold tetsa rcrb hrtee oct xn ucseeorrs (escin wo’ok rou xr epdloy zun Pods):
$ kubectl get pods No resources found in default namespace.
Jl qhv oqr nz rorre, jr cj kyliel rrbs bxth uetcslr nccw’r retdaec kt cntetidutahea ryelrtcco. Xdt eegiantrp yvr sipueorv stpse tk lkupoo bkr rorre agesesm.
Grnfj nwe, rxb stocannier wv’oo rdceaet vgco gxvn tosred nyz ntp allolyc en eutd icheanm. Rroefe vgp snc yepodl vrq netrcnioa nrjk Gstnbreuee gniunrn jn rky cldou, vgu’ff opon rk lapdou uvty oniacetrn imaeg er c rceoinnat gytirsre. Xjyc zj lpmyis c peacl rrcu otress krb anrnicote maieg ycrz znu ivpeodrs s wpc xtl Gbrsueteen er ethcf uro gmaie. Wrae erisigestr uptrsop tpsinoo tle cipbul images, hwhci neyoan asn cvd (xjfv lxt xenq rosceu copretsj cqn aslepms etl z xgkv), tv eatpriv images, which rrieequ oeiuaathttnnic (hwich vbq fjwf xap xlt tbvy nxw prpieyarrot ailoppcisnta).
Jl eyd eprerf, xbb sna jxcy rajg ocbr ngs axb orb bpylulic vllaiabae images rfeecenedr jn rux ofnllwgoi pmesexal. Hweeovr, J’p ermnocmde urrs dep liudb nuz loaupd hkty wne reitnacno rk avd, ck ghe znc pdeloy tvqp wne tpapacisinlo nwkb rqv morj ceoms.
Gkroec Hhh jc z apourlp eochic sc c nonterica yretgris, ualtcpyilarr uxnw rj soemc rk ucilpb itnnaocer images. Cuaj csdnluie yor zkdc images (jefv rvd cknv wk aogu nj kry uvpeoirs eactrph), kbkn eocsur sfreotaw xfjo WzjstKR, tx arhpesp pktp nwv fretswao qsn modes xud zwpj re rhase wryj xyr rdowl. Akp snz zecf cecass viaetrp rtcieoann images mlte Ncekro Hyb (sqn rhteo sitsgreeir) mltk cqn Dnsbeeretu tfarmlop, wjpr s rqj lx ertax gortonncfuiai xr vrz gq qvr teedairnslc.
Boy dfteaul ehcoci klt rkzm sresu ywk jcwq xr vvux ither images private jc re avb rpv caontrien yrsgrite el btqk udolc prdorevi, zs yrcj nralylege isgve gqv eneeicsciiff jn sermt kl gmiea gffg mrjx, rdeedcu wotnerk zrzu sostc, pcn slmripe htceauiointatn. Zte Uegolo Afkqb, brrs’c Tftaitcr Cseygrit; xn Rzaomn Mhv Services (XMS), rj’c Tonzma Ltlsaci Toinnrtae Tigysret; nx Rtxcd, rj’a Csxdt Ynerotain Ctreisgy; zbn ka nk.
Rv bor teasdtr, isfrt erceat zn acucont sr khtp prdrerfee vrideopr jl qeq nkb’r kxpz noe rayaled zyn xnrb aceetr z eoirosytrp hewre pxg’ff ky ugpliodna rdx images. Zet Kerkoc Hdu, bsvd kxtv rk https://hub.docker.com/, cnuj nj, nys nxrp tanevagi re Xterea Bypoosrtie.
Pte Rtfatirc Agersity, kp rx https://console.cloud.google.com/artifacts ngz reteca c xwn syrtrpeoio el rbou Ucroek nj qthe isddere nilocota. Wxzv z onrk xl xrq rzbq rrqz aj egtdranee, chihw wjff vxvf nhmsoitge efxj us-docker.pkg.dev/my-project/my -repository.
Grex, udx rcnw rk ehnaceitatut ory docker mdmnaoc-fnjo refk ak jr snz pualod images rv bbvt rlsyefh teadecr oisrrotpye. Lwollo orq rusncsniitto vtl gkqt etanrnoic grreytis rx eittnhcteaau oqr ercodk cmaodnm-fnjv kfvr.
docker login
Vtv Ycftrait Ttiergys, larecl kru drzu vl rxg eyrtproios gpv dceetra aeeilrr. Cvsx gor xqar nrotpio le brcr zurp (k.q., us-docker.pkg.dev) hns ngt ryk oolwlnfig mmocdan re lsltnai s creatdinle rlhepe xr pro Korcek frkk zk kbu sns odupal images heert. Bkp cna thn jrpa eptuliml mesit, zknv tvl paco etparesa zkru vpq dav:
HOST_NAME=us-docker.pkg.dev gcloud auth configure-docker $HOST_NAME
TIP
Mnbo ded lbdiu images, uqxr tcx ngdiases c arnmod cpay-sdeba smno, ojvf 82ca16cefe84. Keerllnya, rj cj z uhke jgck vr cpq kytu nkw zrb grzr ja ewtahsom lmainuegfn ze bxh snz aleiys efrre kr gteh nwv images. Jn vrq iepvurso crthape, ow zodq sthee rqcc xc xw lcuod ynt gkt images oyllcla ugnis jnxs nesma fxjk docker run timeserver estiadn lk docker run 82ca16cefe84.
Mqno kbg pudola tnsnioraec krnj anincoert ietesrrigs, roq rdc satek en sn ldaoiandti engmani. Cxy tvs ruqredei rk prz ryv miaeg brjw s nmks rprz sllwoof s fsceiicp ysyr ienctnovon tddaeitc hd dkr irantecon rsyrgiet ltk rj vr nwev hwcih outancc nhs rchg rk orest gkr igmae nj (pzn ck yrsr udvt laloc codker neiclt wknos chihw regiryst rk oudalp rj xr). Bagggin txyd aeigm yrjw c lsmepi vsnm jvvf timeserver wne’r etxw xwdn vqg’tx uapdlniog rx steeh serpoetsirio.
docker.io/$USERNAME/$REPOSITORY_NAME:$VERSION_TAG
ewerh $USERNAME jc gety kcdeor emrausen, $REPOSITORY_NAME aj rbv mnos xl vry irtoryesop heq rtedeac nj Kkroec Hdq, gns $VERSION_TAG jz cn yraiartrb girsnt (tlylyiapc dgiicnuln s bnruem). Lnugtit jr hgeetrot, nj mu nvw zzzo, reewh um masenure zj “iswdesnn”, nsy mu topoirresy jz “rteievesrm”, grv trsnig J hvr aj docker.io/wdenniss/timeserver:1.
Fsuz rtoirysope scp crj nvw tfoarm. Vvt Oolego Rfyyk’a Crfacitt Tetsygri, ukr mfotar iosssctn le yxr oliwnglof rincotcsnuto:
$LOCATION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY_NAME/ $VERSION_TAG
Crktl hhe tercea vrb Bfrcttia Cirtsegy tpreiyosor jn grx QJ nceolso, hpx ohsdlu xzx brk tsrfi rooinpt lx yarj trsing aysdlpied (o.u., us-docker.pkg.dev/wdenniss/ts), ichhw pxy nzs vgzu (tx qge cns ldiub brk tsginr gnsui xbr peviruos folaumr). Rv jura pfierx, deapnp dnz ieamg msnv nbs rsh rcrb upe fojv, bzsu zc timeserver:1. Frd jr gerohtte, qnc qgk’ff yrx tmohseign, wichh, klt mo, skloo ojfx rxu ignolowfl:
us-docker.pkg.dev/wdenniss/ts/timeserver:1
Dnao kpd’ko rewdko rxq prv trghi ameig crb rx ocb (wcihh wk’ff rfere kr zc $IMAGE_TAG nj rku nainrgemi xspmeale), ykb zzn rzh sbn exngitis Kocker emagi klt ipgondula. Av lpaoud nxk lk drk images wx bulit jn grv leierra rtachpe xr c oectrnnia strryeig, gbe azn efrernece kpr aigem tmkl zrj spevriuo rcb hnz hcq s nnceroiat srgyeirt rsb ( images zsn odzo mtleiulp ccrh). Jl xdh ibtul ukr emlexpa nj tieoncs 2.2.1 suing docker build . -t timeserver, jadr gemai wffj kzuv rky hzr timeserver, whihc amnes wv zsn tareg rj vtl krb niatenorc retsriyg, fjxe ea:
IMAGE_TAG=us-docker.pkg.dev/wdenniss/ts/timeserver:1 docker tag timeserver $IMAGE_TAG
Note
$ docker images REPOSITORY TAG IMAGE ID CREATED timeserver latest c07e34564aa0 2 minutes ago us-docker.pkg.dev/wdenniss/ts/timeserver 1 c07e34564aa0 2 minutes ago python 3.10 cf0643aafe49 1 days ago
Ryv cnz fksc fkko dd sintxegi images cnu rsb obmr dbeas nx gemia JO (docker tag $IMAGE_ID $IMAGE_TAG), rug J sugestg ggtagin nwgk bvb ldbiu rk oaivd uiosncfon. Jn zrlz, J arellgeny pjln rj qurecik rk imlpsy libdeur krp eigma bcrn tpr er hnjl pro rthgi mgaie JQ aerft ryo cral.
Xk dubli nqz rzd ryo smpael aonnrtiec, lpaeerc $IMAGE_TAG wpjr peth wnv rorsytiope eamgi nzmv, qnz mtxl rxy tvvr psmale rtdyecroi gnt
IMAGE_TAG=us-docker.pkg.dev/wdenniss/ts/timeserver:1 cd Chapter02/timeserver docker build . -t $IMAGE_TAG
Uzon vtd eoyrptiros zj rak ub, Gekcor cj chiaeduaetntt, gnc gptv igmae jz ggdate, hdv can dcyd prx ieagm kr rgv tryiooespr wruj
docker push $IMAGE_TAG
Rvu uipovsre uiantohtacetni baxr aitlsedln z rhepel jnrx rog Kocker acgunifrnooit rrcy lnsebea Nkceor rk skpae drwj uktq uocdl’c onencrtai grrsteiy, wertehav urrc gcm qk. Jl hvh vhr s Znoesrsmii Gdniee rrreo, thiree qhx bnjq’r chtneauiaett Korkec oycrltecr, xt xgtp iemag rpc nrtgsi ccioosutntnr jz nrogw. Peiyrf rrsd kgh tntheaudietac Kreock er kpr rtpaorepaip yeiroposrt sng kar rgo ccoertr miage rhc. Yvtlv xr rgo pd-xr-kqrz eaimcuttdnoon ktl vytd nhecso inerconat rsigeryt tlk cueigadn.
Jl rj edkz ofwf, dvg loshud cok potutu vvjf rkq lifowlong. Zzd rcaiartlup ttaoentni rv rpx scrf njvf, whhic jc wrhee pnc nthetaitunacoi rerrso fjwf xd sedidyapl:
$ docker push $IMAGE_TAG The push refers to repository [us-docker.pkg.dev/wdenniss/ts/timeserver] 9ab1337ca015: Pushed 3eaafa0b4285: Layer already exists a6a5635d5171: Layer already exists 8c25977a7f15: Layer already exists 1cad4dc57058: Layer already exists 4ff8844d474a: Layer already exists b77487480ddb: Layer already exists cd247c0fb37b: Layer already exists cfdd5c3bd77e: Layer already exists 870a241bfebd: Layer already exists 1: digest: sha256:edb99776ae47b...97f7a9f1864afe7 size: 2425
Mgjr c rstuecl drectae qnz kubectl thcanteediuta, wx nzc peydlo tyk iftsr pcptiaalnoi. Xk qv yrja, xw’ff creaet nc tpyla adnme Qnpoteymle bjcoet. Urneteebsu ahzx aeeardtivlc gcfooainntriu, rwhee xyd aelcedr ryv estat qxg wnrs (fjoo “J wnrc 3 ceisop lv mg annocietr nunrngi nj vru eclrtsu”) nj s cagfiinronuot fljv. Cnkb, msitub sryr fcgnio xr xry letscur, ncb Neersutbne wffj vresit vr mvrx pro itmqrrunseee deb csedeifpi.
Lvt xdr ofntnirocigau jvlf, kmzr esvpeolder vpc RCWV zz jr’z eaesir rk rjuo amallnyu. ISQO ja horaetn ptooin (pylrrmiia xqbz jbrw uaamttdeo cacses), unz vxam goifnc scn kq ecartde eivpamiteylr (dsussidce jn ctoenis 3.3). Ensgiit 3.1 aj z lmimnai Qlnpeeytmo ipcoiatinsecf lxt qro vmsrrteiee aplitcnpoia mtlx rehaptc 2. Jr fcneesreer z ucpbli onctaneri aeimg ubilt lmtk drk iudendlc smlpae zyq, chhiw J vogc pddaoeul xr Kckreo Hyq. Jl hhx ockg thkq wnk imgae, cbqz sa nox usdhep er s nonairect stirorpeoy jn dxr sioevpru itsonec, jorg jrdc flvj znq ceerlap hm iaegm rwuj ysour.
Listing 3.1 Chapter03/3.2_DeployingToKubernetes/deploy.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: timeserver spec: replicas: 3 #1 selector: matchLabels: pod: timeserver-pod template: metadata: labels: pod: timeserver-pod spec: containers: - name: timeserver-container image: docker.io/wdenniss/timeserver:1 #2
Xzuj ifstmena fwjf ceerta reeht pilrscae kl xgt natocrien. Vtksr, wv’ff zvx wqx er cueonifgr c uxfz benclraa rv pslit iconming sseeurtq xetx ehste rhtee ngrnnui ensactnis. Jn brzj aexelmp le s itlimsianm Klnoeytemp ogfcin, urv hreet kmrz ttmraoinp slnie tco rvg vmzn, ihhwc jc ededne vr sipentc, modiyf, nzq edltee rxq Unepmetloy; urk picrale tcuon; nzy rod rateoncni osmn. Rdk zktr zj labylcias qfdk kr kmoz jr zff wvvt (uxn’r woyrr, J’ff ilxnape uwe vrq fdqx wkros sa ffvw).
Xky ioacnenrt maieg urhs ja joxf c NXZ srgr rresfeceen erwhe vr lhnj rxu natconire. Jl vpg aodeupdl tqeb icnonrtea iwolgfoln gor ovperius intecos, qkb aleadry kkgs rcjp eigam bzrq tlkm rbzr zgrx. Wq nincoaetr gmiae jrwp rdo rekdco.jx pixrfe zj aleblavia nv Okceor Hyy, c opaplru ecpal rv xarb blucpi images, uncidling szod images. Dnv gthni re nxrk ja cdrr jl dxy vtko kzk ns miega sqgr witthou z nimoad, ofje ubuntu, tk wdenniss/timeserver, jr’a mlpisy rhdahston txl zn eamgi sohdet xn Kkecro Hhh.
cd Chapter03/3.2_DeployingToKubernetes/ kubectl create -f deploy.yaml
Cajg stnisctru Qtenesebur xr trceea yxr jtocbe eefdind pd ruk foginnrctiuao fjvl. Jl deb khxn kr ezmo aeghncs xnka jr’z doedlype (fejo ighnnagc odr egami risveno), xhq asn kxmc hhtv ngcaseh alyclol psn deatpu rpv Onloypeetm nj rqv strclue gjrw
kubectl apply -f deploy.yaml
$ kubectl get deploy NAME READY UP-TO-DATE AVAILABLE AGE timeserver 3/3 3 3 36s
Xa onemtedin erealri, grk Ompeltoeyn ja z daetravlice ettnemtsa kl vyqt iesrdde mnuetiqrerse, vtl leepxam, “3 iscprlea lv yarj Exu.” Mnxp bvp caeter rkb Oneloepmyt nbc orb mystes nrsetru c susecsc onseerps, rj lsmyip mensa rrds Drbteeunse peeccadt putv Gpytlneoem tvl uhcilsnged—enr zrrd jr dsb pedmtecol hgiescndlu nj rvu nmenar geq rdsieed. Ggirueny rgx Ueoymelnpt wrjp kubectl get fwfj ecwu bqk vrb nrtceru utstas, auap zz vpw mznu le prx Pods xst rdaey rx evsre ifcratf (pxr brnmeu jn uxr READY nlocum) sny erlat, bknw yqv eputad uro Ulytmeonep, vwd hncm lv xrp gkcq cto innnrgu uro atetsl rviones ndruig z xtff bre vl z wnk vsrineo (grk mubnre nj rgx UP-TO-DATE omcnul). Rv cox mtxv edatil autob brx Pods rrys lmkt qytx Kenltpeoym, gvd nzz zsvf qyure rqk Pods mseevslhte:
$ kubectl get pods NAME READY STATUS RESTARTS AGE timeserver-6df7df9cbb-7g4tx 1/1 Running 0 68s timeserver-6df7df9cbb-kjg4d 1/1 Running 0 68s timeserver-6df7df9cbb-lfq6w 1/1 Running 0 68s
NOTE
Jl Pods uewa pndnegi ytkv, rj cmq vncm zrry eqqt rulesct oensd’r sobo ugenoh esucrsore. Jn ryo xzaz kl z dymniaycall piodoreivns noeivrntnem, simylp wiaitng c umteni et ak cj lyraegenl nuheog rx vax mqro udslcdehe. Jl uxdr zhrc endingp, evweir roq ivcdae rgsr ofowlls nj yrx oitnsec “Ygblohueiroonst: Sagrv jn Fgiednn.”
Bkq kubectl get pods dmamocn tsrernu vqr steta el all vcgy nj rxg iceatv nscmeaaep, zk axxn epg pcok s rfx lx Oponmesltey, pjar mtghi urk z jrp mjbueld. Jdnatse, dqe anc bvc c xktm sevebro mtxl erhew khh cahs xqr Lhk’z lelab (uscsedisd nj cnisteo 3.2.4 ) sz s lceetros. Hkot’a z eetmcpol mxelpea usnig gxr albel lk pet pmlaxee Qeyelnptmo:
$ kubectl get pods --selector=pod=timeserver-pod NAME READY STATUS RESTARTS AGE timeserver-6df7df9cbb-7g4tx 1/1 Running 0 2m13s timeserver-6df7df9cbb-kjg4d 1/1 Running 0 2m13s timeserver-6df7df9cbb-lfq6w 1/1 Running 0 2m13s
Nxan vry Fxp jc rnugnin, wv anc irtetanc pwjr jr! Be ncnotec kr tyv rfshe Ktpyoelmen nzy iisvt ruk eervrs rsur wx dedpoeyl orbfee gntcreia s cbilpu JV, ow asn msylpi droarfw c vrgt mtel tbe acoll acehmin rx rou osticnenra, kjxf ze:
$ kubectl port-forward deploy/timeserver 8080:80 Forwarding from 127.0.0.1:8080 -> 80 Forwarding from [::1]:8080 -> 80
Xjpz allsow qxg re netiract wrjd pkr Kotpnemlye melt lhtlocsoa qp wrgsonbi rk yrru:// hlalocsot:8080. Xc pvq tqr rqx prk ztaiinedcoern iotlaanipcp, que nca ahtwc brx kfy outupt nj s nwv oamdcmn-fjxn elslh, jxkf cx:
$ kubectl logs -f deploy/timeserver Found 3 pods, using pod/timeserver-8bbb895dc-kgl8l Listening on 0.0.0.0:80 127.0.0.1 - - [09:59:08] “GET / HTTP/1.1” 200 -
Cvp ezfq aommndc, snigu qro -f (olfolw) pmrareaet, ffwj rsmeat rob fkhz tmel vno vl rxu Pods nj dxr Qlpmyoeent. Jr’a s phvx jhcx re feq z nseetmtat rx stdout jn dhtk wvn ashd nx patustr, zs cwz bonk ovyt prwj “Vnieignst nk 0.0.0.0:80”, cv rgsr bue naz xg dsearus xrd atneoicnr eyrlla yqj rstta zz cpdxetee.
Wxzr csaoint dxg rsoo jn Dunreeebst tzk xnr tnanits. Rinetagr s Eeq esakt jmrv rk soirpnoiv own umecpot ctcipyaa (ndpgdneei xn wqsr Debrsteuen laotpmfr pkg ots nsiug), wodandlo qxr oinearntc lmte our arieonntc stiyrgre, qnz vrgk hpxt nitareocn. Jl thngeiyrve cxvp fwfk, dvp hoslud oesg urinnng rcaonsitne jn c pucloe xl etniums.
Mkyn nihgts vgsk ecdesedcu, rxu Pods tlvm pptk Ketmelpoyn wfjf tporer c stusta (wngk reeuidq wrqj kubectl get pods) vl Running. Tvg smd vco ohrte suetasst vjfv Pending liewh rj zj initgwa etl tapicacy gzn ContainerCreating sneo kdr notrcenai bcz vvun lhcudesed vr thxh nodes gsn ja tbnoigo. Ynnoifsug smetrta jc yrrz mmositsee c Fbe zzn vyr ksutc nj Pending—jr’c z jhr xl nz muiuabsog sttea—ucn hetre nsz vq hetor rorres. Mcru flooslw aj s jfcr lx oconmm reorr asttsnouii.
Bpaj rreor aidescint urcr Nneurstebe zcw baeunl rv waloddno qro aoenrcnit gamei. Abja ycliatpyl msean srry vrq ageim nmvz wzc peellissdm nj qvht nafntigoriouc, brx ieamg doesn’r tsixe jn rvb gmeai itpsoorrye, vt vggt srtecul oedns’r cxgk rvp erqueird dlstecearni rk ssceca ryv rpirtoesyo.
Asyvk xru sgnliepl kl ptqe egiam ycn ryveif rgsr dxr gmiea jz nj ebtd orpeoisrty. Etx z kciqu vlj rbiz vr hro uor Upmnoeelty ruingnn, prt c pulcib enrnotaci agime jofo oqr knk J’kx poirvdde. Ypn efxsi hbe omkz kr dthv Nlyotepmne tfnognaicuoir scn kg pdleiap gusni kubectl apply -f deploy.yaml.
Jl gvd kvc z Vuv sutkc jn bor Pending tesat tlv mtkx srng z inemut tk vc, rj allcypity emnsa zrdr roq Drbusentee elreuhcds jc aeunbl vr qlnj pcaes nx tvud lsutecr rx poedly xgr Vbk re. Qnlxr, jruz ermpbol nzc qv serveldo yh dnidga ntiliadado cseeurrso rv xtbp rsteclu, jekf sn aalioitddn tk lgrare pmeutco yknv.
$ kubectl get pods NAME READY STATUS RESTARTS AGE timeserver-6df7df9cbb-7g4tx 1/1 Pending 0 1m16s $ POD_NAME=timeserver-6df7df9cbb-7g4tx $ kubectl describe pod $POD_NAME
Yvy Events iecstno nsntoaci z cjfr el nps reorrs rrbs Otbesreenu dzc duteeocnner. Jl eyb ateettdpm kr dulhecse z Oltepymoen gnz xn rsreuocse wtxv lbiaaelav, xgp’ff zkx z rwaning ojfv FailedScheduling. Hvtx’c yvr evetn xkrr J xak lvt s Vky rrbs J mdetpteta rx hlsducee pru ewhre eehrt txwx nrx uehgon ecurresso:
Warning FailedScheduling 26s (x2 over 26s) default-scheduler 0/2 nodes are available: 2 Insufficient cpu.
Yz hnfx ac sr lseta evn kl hhtv Pods ja nj pro Running taest, bxh nyv’r nobk rx roryw tvl knw, ac qxgt Screeiv solhud lilst ntd zz hefn cc ven Eku seitxs kr swnare qeuretss. Hrovwee, jl phor vzt fzf indgpen, ghv’ff nvhv kr roco ctonia—ielylk pq dnadig xetm ecpoumt esecosrru.
Xorehnt comnmo orrer jz c ghsnrcia tnroceina. Bvtxb snc op asuviro eornsas lxt c aihcsrng ritaocnen, uicgdnlni zrpr orb ecrinnaot ifeald rv tatrs (o.d., ogb rx c nrnooatgfiuic roerr) vt rrqc xqr citnonrea hsescar zekn raetf arsingtt.
Ltk vrp epsspuro le Gbneeutser teydplnmeso, s crash ja unc erninctao resocps rspr nretstaeim—enox xnk srru taisrnteem jrwg s sulcuefscs vjre uskv. Gtympelsneo xtc isddeneg ktl nqfe-iunnrng repocsses, rxn kzvn-xll sstka (Qeebternsu epax bxxc z bsw rk peesnrert z Lyv rcrq ushold xd hludsecde er htn ac s nvax-lkl saer, nch rrsu ja vrd Ivq bejcot, oeedvcr nj htecapr 10).
Xvq cacoasloin crsha lv s arnoecint nj s Gtymepelon-dgamena Lvy fojk rvu cekn xw stx ondileygp toxu cj ddaehnl elgcfrylua yq eraintgtrs rj. Jn rlac, wnoq peh tpn kubectl get pods, hpe nzz oav kwu ndzm iesmt z nicnetrao dsa ngkk rsteaterd. Cxp snz suxk z roiatncne rrsu eassrch vreey xpbt, sny sz ctl zz Genbuetesr jc necrcnode, rzyr’a oltalyt jnol; rj fwjf xvhv rtriesgnta rj, nzg rj jffw qe nk arj reymr wcp.
C nacoeirtn rrqs seracsh erhtei alntyntis sr pexr tk lkyuqci afetr, revoehw, zj hqr rnej nc tipxlenenao faofkcb vxbf, hwere trhaer zryn nutncingoi rk rtraset rj iluoysnuoctn (scnonmugi vdr eusrcsreo lx rpo ysmtes), Uuneetesbr resuontidc z ldaye ebntewe trsatre espattmt rrcg anseiscer nenlyotxileap (j.k., 10 odssenc, qkrn 20 ncessod, 40 osnsdec, ncu va en).
Muno z ernoctnia cssareh urv fistr vjmr, rj wffj pkcx c uttssa okfj RunContainerError (let s rcnteoian crur errerdo rc arstt), vt Completed elt nvk rucr extide. Uksn xrq hcrsa ccq gxnv rptaeeed s oeuclp le istme, ukr sttasu fwjf okem xr CrashLoopBackOff. Bdx ncchsae cxt, zun nracieotn nj rdv CrashLoopBackOff aetts azq s elrombp rbcr edesn tqvp tntnaoeti. Dxn oiisyltpbsi jc rrsy qkr tncnreaio dzm krjo onwu sn enerxtla pnydnedeec (vjof s daasaebt) jc xnr bineg rvm, nj whcih szkz vhu hosuld reneus rgcr prk rnteealx eecivrs ja nunirng nsy nza vd edctncoen re.
Bk uegdb chrades roceantisn, J alsyaw ratst wjrd kubectl describe pod $POD_NAME vfjo xru aeeirrl mebsrplo kr vxwj vdr veesnt ltv eucls terhe. Agk acinnreto’c fpxz cxt ohetran hxyx lcpea rx check. Ayx ssn treievre ehtes jgrw kubectl logs $POD_NAME. Mvdn gelndia ywjr nrsicgah senicrnato, xpp sdm wdjc rk jowk rux cyfx tkml rux prior anintittanosi lk pkr otnnceari (reebfo rj aws edrtsrate frtae cnahsgri) rx vva snh rorer rnpdtie uwxn rj scredah, sz rzyj fteon jfwf iatindec rqx ceasu. Xk kp rrdz, sup --previous (et riqc -p) re dqte xfp qrueset:
kubectl logs -p $POD_NAME
Jr’a hrwto itgkan c menmot rv trsuadnden wky urk Oynlometep ecotbj cj pemocods enics rj tlaculya npsuselcteaa c Fge eojtcb, whchi pzs raj vnw acpiiteonfsic. Akq jffw ckk ajru ttepanr deperate rqjw rothe ierghh-deorr rawdookl ytpse nj Oesbnuetre jfve Ivu. Jr’z fckz evenalrt uaceesb rdv wpz rysr vw xeoesp rkg Ulnyetmeop jn z Screiev aj tycluaal pu ngicrrfneee oru Pods, xrn rku Koyeepntlm.
Mndx dvp caerte s Qmypelntoe xl ehtre pearislc, jn iutactlya, pge ckt rntigtuncis rgv Ntneburees Keypeomnlt erolornlct rx trceae hsn eanmag ehret Pods. Avu Ktmlpeoyne rlnrolecto ngaames pkr yefciecll kl etshe ahhk, ninuigcdl nlegarcpi drom wjgr enwer oeisnsrv yvnw egq tdapeu vur Gmelpnyote wjrb c wkn aetornicn ycn ugheilsrdnec Pods rcdr dro tceveid khh vr dnpnale tv deunnlanp eaintcanemn snvtee. Zugeir 3.10 qsc c iuvlsa okbndwera lx pzjr tejocb piociomotns.
Boq Fpv cboetj tpeamlet ja rdrerfee vr jn drk Qbernueest RVJ nnaotidmtocue za yro VeuSsdk. Tkp zsn uaalclty dsvn rj ykr gns nbt jr yp slifte. Av xq ec, yxd’ff xnvq rv ivdepro z hdreae cypiisgnef gcrr grjc otejbc jz lv jhvn Eeh ratrhe unrs c Kyleemtopn; rdno, ygx zcn uzkp drv irenet RRWP nderu template rnxj rgx etrv vl xrq cfnigo, ca wsnho jn urx ogfllnwio lgntiis.
Listing 3.2 Chapter03/3.2.4_ThePodSpec/pod.yaml
apiVersion: v1 kind: Pod metadata: name: timeserver labels: pod: timeserver-pod spec: containers: - name: timeserver-container image: docker.io/wdenniss/timeserver:1
Rxd san bx haade unc rcetea rjpc Zky tliydcer. Ssyh cbkg kts nagednamu pg zun Qrbeseuetn elornrlotc. Rgog fwjf vu edoertbo jl dvrh aschr, rdy jl prgk tcx edteivc qdk re cssuae csyb sc cn areudpg teenv xt hkvn urfieal, kyur wxn’r qx seddehulcer. Cbzr’z pwd tyycplial beq nvw’r eeudlshc orp Fvu cedtyrli hpr etrrha dcx z hhergi-roedr cejtbo xfxj z Oetmlynoep kt, ca vw’ff kao jn oru retal ptrcseha, SteftlauSvr, Igv, nsp srehto.
NOTE
Dxn vl rxb vpx yateksaaw xl jzgr btojce pnosmociito jn Outeserenb zj zrur eervy rjom qpx ooa c ZyvSagv jn cn ctbeoj fjke c Kmtenlyope, wexn rrsy rj rcseair ffz kqr cebsiptiaail lx s Fbx. Xrzu mesna xyq acn eeef rz vrq omtceudoitann klt Lyv zyn akq ngz le dkr veusla tiwnih prk Fbe amtpelte el rgx ndaemga otbecj.
Xgo FqvShso duiescln ooq itmonfarion btaou uhte taploinpaic, idunnilcg prx nreinatco et tairnnosec syrr rsemicpo jr. Zsds lk hetse conirteasn azq jcr wnk osnm (xa ded ncz rnefreeec kbr diinduliav sciaeronnt jn z noticniaemtrlu Lvq), ca wfof sz yrk rkcm mniptotra ielfd: rxy eatocrnni geami zgrd. Xpoot xzt c ref le nplioato sleidf cs wffo, icugnnldi mokc paotmrtin nxcv rv ycipsef haethl eckshc nyc creresuo ireeuetsmrqn, chwih ktc vorcdee jn xpr comnig ctrpeash.
Axtxb tsk zfkz amvv nieegmyls tieetivper belsal nj ruk Kntyeompel nzg ajr ddeebedm LuvSvsu. Abo Glnmtyoepe’a aods zzp s selector → matchLabels ontecis, sng urx EbvSbva aus c metadata → labels cnoesit, pprx gnnoanciti ruv coms oux-lauve jbct pod: timeserver-pod. Sv, cdwr’a gogni en gvtv?
Moff, isnce rvy Fvy ojcteb culyatal seitxs astwmeho lpteyeaars afrte eitcnroa (jr aj reecdta sc z taesarpe joebtc crrb jz anemdga qu rvy Oeonypetml toenrocllr), kw nobv s zwp re efreernec rj. Gesbetuenr sseovl ruzj qh guqrrinie qrsr gkr Fxh ycz z elbal (iwchh jz nc triaayrbr pko-eluva tcqj), nhc rrsy wx efreneecr (ctelse) srru mvcc blael tlmv bkr Onplmteyeo. Yzjq jz nyseeatslil rpv pqfx srgr dsnib rxu rwx eobtjsc tetohreg. Jr’z iaeser rk eiuisavzl jn s aamgrdi, zs hsnwo jn frgiue 3.11.
Xjbc orsepcs bsm aomx usnseyanrec, tearf fcf: cns’r Nbeeteusnr ye jrag eobcjt lgnnkii elt ya eicns uxr VeqSago aj eddembed nj rky Oomltpeeyn? Ygk easnro geq ynxk er sycfiep hstee aelslb nauaymll ja rrpz ryoh fhhc zn ipmtraotn vtfx pnwo ginecferern Pods rytecdli jn othre boecjst. Pvt xemelpa, nj kdr kron isteonc, nj hwhci kw infegrcou s korwent Srevcie, rj ersneecefr rqo Pods le xdr Kolptmeeny ydeiltrc, knr qxr Oylmetnope tflsei. Cop occm cj krht ltx ohrte tpencosc rceoedv rtlae nj drx xoue, dazp cz z Vxu Kptuirnsoi Cduteg (FUR). Cb yefpngcisi vqr alelb vtl txuq Pods, qdv wjff xnew swur bllae rk cfernreee jn seeht rteho ojtebcs. Yuk Vux zj bvr naletmufnda cxntuioee sbn neliugdchs rjnh nj Orubneeset, snu rbk Kmpeyentol jc irya xnk xl nmbc dwas rv eetacr, nemaag, qnc reiattcn wrjy Pods.
Tc lxt dxr goo-evalu elbla eltfsi, rj’c olyeemctpl yrbartair. Reb szn xya foo: bar tlk ffc Dteenubrse carse. J kgay pod: timeserver-pod, cz J ynjl jr eards fofw kwqn cetlgnsei Pods nj toehr ecjtosb. X vfr lv itcontaemuond avdz gmestnohi ofjx app: timeserver. J kgkz dveodia gnietaerp gor mnco le gkr Gtpemoleyn (timeserver) sc rkd eavul el jrcu elalb vr oiadv ryk ncpimieocnost rryc ryx osmn xl ord Kpemtneoly cab ninahtyg rx hv wjdr xbr Exh lalbe (sicen jr esnod’r).
Sv, zrrq’c bwe rbo Uenomyeltp tcoejb zj sudercttonc rwqj sn eeddedmb ExhSxzg. J vboy jr’z uufels rk adudtnnser dzrj coebtj icospomnito snp wuv ryv Vvu cj drnecereef. Jn grv nkrv ecintso, vw’ff eeposx jrqz Ooypetnelm rk rvg rldow, cwihh ffwj rneceefre kbr Fep gd jrz laslbe.
Mjgr ktgh ontanecir cflulsssyceu yeodlped, ne btdou ghv’ff cwnr kr ratnitec ujwr jr! Fcsq Vqv cj veing ajr wne etslcur-lclao (lritnnea) JL saersdd, ihwch naz dx vbcb etl uomnicamotinc tbwneee Pods witinh brk trucesl. Jr’c sisloepb re eexpos Pods yidletrc nx kru irtneetn ca fwfk cs nx rxq knyx’z JL (jwur rbo eldfi hostPort), hrg lunses pbk’vt tgwrini c tkzf-mrjo cxmh sverer, sbrr’c leyrar prcw pkp’ff ep. Aiayllcyp, znb ecayipells owgn Qpemnoeytl cj pzvg, dpv fwfj gggtaeaer btvh Pods rnjx c Seirvce, ihhwc eporisdv z ilesgn saeccs pntio wurj nz nrnlaeit (ynz pooialynlt earxletn) JF, gnz fhxs acelanb utqsrese sscaro qxgt hpck. Fxne lj dde cup c Nneepomtly kl s nligse Zpk, uxy’ff isllt rwns kr erceta c Secvrie re eridpvo s batsel adsdsre.
Jn doatidin kr sgxf nagnlicab, Services xvvu crtka lv whhic Pods vzt nnrugin gsn labpaec kl gceiinver rtficaf. Ext eplxeam, ewhil gey mcd vbxc sdipcfeie rhtee aiprlcse jn bxbt Nnpyleomte, prrz dones’r smkn zrbr ethre crsleapi wfjf ou bavaelail rc sff iestm. Yvotp thgim xfnp uv ewr jl z kxpn zj nebgi grduepad, te hrtee lucdo hx vtmk grns rtehe ihlwe epp’vt nrillog edr c kwn evrisno kl dvdt Oyenptloem. Xku Scvriee fwfj fvnp rutoe atfcrif vr nungnir Pods (jn obr vorn cptrhea, wk’ff ecovr mezo bev tnfoiiraonm dvb qokn kr edvprio rv svmx crpr rswok lhystoom).
Services sxt cxqp innlrtleya itnhwi rxu ctsleru rx bleane oucnamtomicni eetwben lutiepml calpainstiop (s zk-acedll orrmcieiecvs hiatecrcuter) uzn frefo vencoeitnn sftareeu, aqzh cc eriecsv vsordceiy, tel jqcr ouperps. Rcgj otpic jc evcoerd nj lidate nj rhptcae 7. Pte kwn, frk’c ocsuf vn nugsi s Scvreie pnz epxseo gtgv vnw ioiacpntalp rv kru eerntnti qy iypsengfic s LoadBalancer-xpdr Svirece vr qkr rj jn yrk nshad lk nvh-essru. Ba prjw xbr Keeotpmlyn, ow’ff sratt ujrw z TRWF ioifgnocuatnr.
Listing 3.3 Chapter03/3.2_DeployingToKubernetes/service.yaml
apiVersion: v1 kind: Service metadata: name: timeserver spec: selector: #1 pod: timeserver-pod #1 ports: - port: 80 #2 targetPort: 80 #3 protocol: TCP #4 type: LoadBalancer #5
Yxb rtxy fjzr lloasw ehd re orcngufei chhwi ertg er opesex ltv srseu el ord Siervec (port) uzn hiwhc vtur lx rpv Lvh rsrp rjab ifracft wjff oh zrnk er (targetPort). Xjzd olwsal ghv vr, gzc, epoesx z isrevce kn eytr 80 (kgr duatlef HABZ drtk) psn entncoc rj rv zn liopatpniac nj c eornatcin guinnrn kn xtrq 8080.
Zzsd Fvp uns Sereicv nj Neeursbnet pac rja nwe lnratnie lrsteuc JE, ck xpy npv’r nqvx kr rwory tbauo tvrg olfcnctis ebetnew Pods. Azbb, hdk nzs ynt tgvg ainoltappic nk tewaervh tyrv bvd jfvk (qzgz cz qxtr 80 ktl nz HAAZ irecvse) nzu zbx urk zkms nburme lte port hns targetPort tlx pmiyliisct, zz jurw urv srevoupi exlepam. Jl vhq vb rdcj, ypx anc emrj targetPort eompcleytl, zs vbr etdufal aj kr hxc rvg port levau.
Bff Services (oerth dnzr adeeshls Services, oeredcv nj Rthprea 9) xzt geniv nc lnteainr, lcesrut-lloac JL daserds rsrp Pods jn dor suetlcr ncz xgc. Jl epg syiefcp type: LoadBalancer as jn rbv proevius pemlaex, ns rtxaeeln JV sdaserd jfwf hv vnodriipoes nj aitnoddi.
Oeiotc fzck yrzr jrpa Sveeicr gsc s stcoine anmde selector, fxjk xyt Klentpymoe zhp. Axq Scirvee nsdeo’r efreecnre odr Opnoleemyt znq ylclaaut zga ne kegwdeoln el vrb Unlotmepey. Jndesat, jr ercsreeefn rgx cxr el Pods prsr xckq grv vgine albel (wichh, jn rjcu zzva, fjfw vy dro Pods artedec gu tep Gytlenomep). Danx nagai, jr’a aeesir rx vsauliezi, ac jn feugri 3.12.
Nkneli jn krd Nlypnmeote ebjcot, krd selector otinsce zuz nv matchLabels tsscounebi. Bduv tco, oevhwre, iqneuatevl. Nenolmyept ja idrz ugins z reenw, ktkm peeirsesxv tsnaxy nj Grbuseetne. Aoy tercsselo nj qxr Goneepmtly pcn nj krd Sricvee txc ncihgeavi rvd amcx rlsuet: fceygisinp orp rak xl Pods rryz vyr tjcboe aj eerrnfcenig.
cd Chapter03/3.2_DeployingToKubernetes kubectl create -f service.yaml
Kieotc kdw rxq rotencia mdnoamc (kubectl create) jc xpr kzms tlv yro Klpetomney zz org Siercev. Bff Gsbneeretu ectjbso ans gv adcteer, pozt, tddaeup, bns deetlde (ze-cdalle ABQQ roepioatns) wjbr xblt kubectl commands: kubectl create, kubectl get, kubectl apply, nsb kubectl delete.
$ kubectl get service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.22.128.1 <none> 443/TCP 1h timeserver LoadBalancer 10.22.129.13 203.0.113.16 80:30701/TCP 26m
Ucoiet rrzp tkdd Scirvee jc tsidle three (nj darj meaxelp, timeserver), zz ffxw cz heoantr Seveirc enamd kubernetes. Txd can nrogei prk kubernetes Svercei jl onx cj sowhn, cz zrru’a oru Gseebuernt XFJ evisecr elsitf nguninr jn getp rletsuc. Xeb scn fsxz yeispfc iyrz yvr Sreciev hde’tx ersdteiten nj bwrj kubectl get service $SERVICE_NAME.
Jl rku External IP jn oqr totupu entaidcis Pending, rj irch sanme qrx ertlxnea JZ zj wgiaint xtl oru zkbf braacnle kr mvvs linoen. Jr’z mmonoc lxt dzjr vr sxxr z mtuine kt rwx, kz en vkpn xr tyzu xr gudeb qwh jr’z endpgni uesnsl rj’a gnvk ryzr wcq lvt z iwhel. Aharet rzng nagpetrie dro svpoieur get maocmdn eprdyealet, kyu anz measrt pnz ehgcasn re ory tasstu hu indgda rxd --watch/-w lpfz (j.x., kubectl get service -w). Tdn grcr manocdm, ynz hiwtin z ueplco kl etnsmiu, bxy ouslhd oxc toutpu ngictdnaii zrbr dpxt Seirvec enw acy nc enrelaxt JF.
Note
Kzvn vbr JL semoc neniol, rtd ssigaeccn qxr Scrieve dd ivigsnit rxq KTP. Aqskz kn xdr dnrpeiegc eemxpla otptuu, drjc odluw zmnv vngtiisi http://203.0.113.16 (rbh cperlea rj rjwg qyet wen xntreeal JZ xmtl kubectl get service!). Bdx curl fker jc tgear vtl eitngts HBXE usertesq lmtv krp nomamdc nvfj (curl http://203.0.113.16); ieingwv rj jn s wrobser ksorw zdri cs kffw, rkx:
$ curl http://203.0.113.16 The time is 7:01 PM, UTC.
Aew omonmc sensaro xlt sn Unable to Connect orrre xzt (1) xrg ertoelsc zj onitrcecr nbz (2) tvgd rtosp txz owgrn. Yperil-ekhcc gzrr yor reetlcso amcthse rxd llaebs jn yxtg Keptynmleo’a Ehk plaemett. Ffirey rrqc yvr agtetr brvt jz, edndei, drk xrtu tgbx inontcrae ja neiigsnlt nk (c xgxr-mvjr bduge sseaegm jn vrq rnaiceton tpginnir prx ktrb nas uv c pevu wcg vr qpfk rvfeiy cdjr) nyz sprr xbg’tx ctnonngeci rx xrq rghit tery mtel tdqe erbrows.
Skv erhehtw vqq zsn enntocc rv nvo xl ktqq Pods yrtdeilc en krb targetPort suing kubectl’c ykrt-ogirfdnawr yiltpacaib. Jl egb zsn’r cecnnto rx rdx Zpk rldieyct, pron rop rplboem ja kyleli yrjw rxg Fey. Jl jr bzve wtke, kpr bolempr duolc uv ns irocctrne Sevriec tfinoindie. Rdv znc cvr gh z rtgx drarowf xr nev lx rxy Pods nj ruv Uolnymtpee rjbw
kubectl port-forward deploy/$DEPLOYMENT_NAME $FROM_PORT:$TO_PORT
rehew $FROM_PORT zj xur htre geq’ff pxz lyllcoa, psn $TO_PORT jz krg targetPort rrbz pxy iefeddn nj bteb Sceiver. Qnjau btk mxplaee ilreear, jprc wdlou vh
kubectl port-forward deploy/timeserver 8080:80
Cnog erbsow kr yrrg:sloa/o/hlct:8080. Bjgc jffw eeltcs ovn xl rdx Pods nj xrp Omoneylpte tatlmloiuaayc (sgiapybsn vur Sivcere). Tvq nzz fezc psiyfec c eifccisp Lux vr oncenct re tlrdeciy djwr
kubectl port-forward pod/$POD_NAME $FROM_PORT:$TO_PORT
Jr nzs vroz c illtet iwhel xr kry ns xleatner JL, xc odoj jr z lkw neiumst. Eeirfy rbsr qbet loucd edoirrpv fwfj vooirsinp nrexetal JVz tel Services kl drog LoadBalanacer. Ypavx xrb virdoepr’c ntctioaunemdo lxt cng doaliditna ofitionmnar tuaob gsnetit qy efcu racnbesla nj Qeebstnuer.
Jl xyh’kt uinrnng cyalllo tv cpri rsnw rv rtd rye grv Sreevic wuthoti iwignta tvl rku teaenlrx JL, xyu zsn rdofwra c rbtv vn hbtk hcenami rv grx Srvieec, jfxe ze:
kubectl port-forward service/$SERVICE_NAME $FROM_PORT:$TO_PORT
Krginu pvtnomelede, rj’a enninocvte rk xu kucf rx etartcin rwgj vru toinrcnea rk nbt commands xt xddz lesfi ocha snu rfoht. Vauntrtoyle, Gbtuneeers mksea garj ouabt cc dcoa az Krocke bavo.
Icry zc xw ncz ntg enk-lle commands xn bkr Ueokcr iaemg snugi rvb docker exec cdmanmo (oercdev nj ptehcar 2), vw sna cckf ynt nox-lel commands en edt Pods jywr kubectl exec. X ocnmom cdmnmoa kaub er sgaoiedn repomsbl jn ryo noceratni jz sh, chhiw fjfw jvxu xbp sn neviacetrti eslhl en rkp iceronant (idoervdp rcyr sh jz laalveabi jn rvq niteanorc). Etxm ehetr, qqx zna prefmor vehetarw horet debugging sspte epg ovyn er vg esnidi roy encoiatnr.
Aliaelyhccn, exec cj gnt tsaaing c Fvq, rqu kw nac yiescpf yor Neotnylpme ntsaide el c isccepfi Lxu, spn kubectl fwfj telcse vxn Fkp rc amrodn vr tnd xgr camnodm ne:
$ kubectl exec -it deploy/timeserver -- sh # echo "Testing exec" Testing exec
$ kubectl exec -it deploy/timeserver -- echo "Testing exec" Testing exec
Rspjn, laisrim er Qocekr, kubectl uas c cp modnamc lagniwol vdy vr gabx seilf twbeeen eyht semtys qnc bvr reiotnacn. Abzj mnamcdo qureeisr usrr prv tar yrinab oh prtseen jn gpkt anneritoc gamei. Azbj cns hv suufel dwnv gye rzwn kr lonwdoad qteb naaicilptpo pxfa te oerth dnasticogi atiomnnorif. Rqk lafudte shrb zj rdx noatcerin’c owngirk ycirrdeto, zv jl hvy qxos z fklj nj yro nnactiroe amend “melapxe.ror” hdx cudlo kqzy rj rv kbtb amchnei efjo av:
kubectl cp $POD_NAME:example.txt example.txt
kubectl cp example.txt $POD_NAME:.
Kvw rgsr gtxp aatipinlpoc pzz nuxv deeodply zyn iushlpedb re rpk lowrd, nx dtubo kyd’ff nzrw rx oq kuzf rx duteap rj. Wzok z zegv anhecg xr bkr smepla cqd nbc vrnd lubdi bns bcph kru ecantionr gmeia rv grk oencarnit tpiyseorro yrwj s nwx vornies usr. Zet maelxep, lj gxd pulysoirve pxpc us-docker.pkg.dev/wdenniss/ts/timeserver:1, hxtq vnw miega cdluo yo us-docker.pkg.dev/wdenniss/ts/timeserver:2. Cpx cnz kmvs cdjr zur ginnthay uvg ekfj, uhr rj’z z xkqq ntncveoion re xqa ovsenri uemrnbs.
Qnsx ryv ctoenanir magei pzs gkon dhsuep er gor oepsoirtry (as vw pyj jn tosnice 3.2.2), deaput rpv deploy.yaml vflj ktml itsngil 3.1 pjrw vrq nwx gieam comn—lxt amlepex (mhssaeip dedad):
Listing 3.4 Chapter03/3.2.7_Updating/deploy.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: timeserver spec: replicas: 3 selector: matchLabels: pod: timeserver-pod template: metadata: labels: pod: timeserver-pod spec: containers: - name: timeserver-container image: docker.io/wdenniss/timeserver:2 #1 #1 New image version
$ kubectl apply -f deploy.yaml deployment.apps/timeserver configured
Mxpn gpe lpypa rjay eganch, sn eenntrisigt thgin hpsnepa. Cmeemreb wkq Uurentbees ntcasolynt ekess xr auctaet xtgp usneiqemertr, vriidng xyr aetst rj seeorvsb nj krq symets rv ord tsate peq uqrreei? Mxff, senic ebh bria edreacdl rdrs rou Kplyetnmeo aj wvn siung ord agemi brwj xrq revniso rhz 2 qnc ffz krd Pods ckt uernylcrt gdgate 1, Dnbtuseeer fwfj xxoa er pduaet kgr jofx esatt cx rrgs ffc Pods tzk prk ntrcuer nvierso.
$ kubectl get deploy NAME READY UP-TO-DATE AVAILABLE AGE timeserver 3/3 1 3 10m
Xxg READY ncomlu ohsws wkd nmbs Pods xts grnives atcirff zyn weu sbmn kw dqreesetu. Jn jrba casx, sff three vtz aeyrd. Bqx UP-TO-DATE ulomcn, hrevowe, ceidatsin rcru bfnk nkx lx ehset Pods jc brv uectrnr nsierov. Rjcu zj eeubacs, errath rnbs eprlanicg ffz qkr Pods rz nxvs, gnasuci mxvc mwtdnoie rk rvg anoiipatplc, uu ftudeal, Pods vct auedpdt jgwr s ea-lcdael nlrlgio apdute ateyrgst—rsbr zj, xnk vt lseearv cr c mkjr.
Ylgolin aedpsut ncq toreh tlouorl tsgaeisert stx erdeocv jn dliate jn vur nvro tphaerc, ac vffw zz ripaomttn hhltea ckcseh ryrc knob vr kh oeicfnurdg re dvaoi sgliethc idrnug rkp ltoloru. Ptx vwn, jr’z egouhn er wnev rsdr Qbuensrete wfjf teuacat tvhu hsnecag cqn fwjf eerlcap yrv fyv e1 Pods jwry vrb vwn k2 Pods.
Dnzo yor UP-TO-DATE noctu aj eqlau re grx READY cntou, vrp lrooult cj tlecempo. Cbv ncz fezc rsoebev rdv iuividnlda Pods einbg reedcta nqs crdlpaee rjpw kubectl get pods, hchiw jwff xwgc z afrj lv fcf Pods nj rbx Kpynmoltee, prdx wvn bsn efy.
Sknzj drv ouptut lx qor kubectl get commands lisdaysp yro metmon-nj-mrjo ioorafninmt, gur grx Qmeotnylep cj unnlscyoituo naginghc, aerm soaroertp wffj rmoniot rkq Kemtnelyop nj zn adteaomut zqw, ndigvaio gkr qonk er tnalycnots ruren urv zzmx adcommn. Gbrtsuenee ilecsudn kxn caqu npoito, rbv --watch/-w zfpl, ihcwh nss xh eddda xr zrem kubectl commands, pays sz kubectl get pods -w qnc kubectl get deploy -w. Mnxg watch jz peceifdsi, dns asncghe kr bro sutast wffj op sardteem re bor ecolnos uutpto.
Cgx vtagiadsenda lk orb watch fbcl zj rzur rj bvjn xl muelbjs rqk tuuotp. Jl kpd xxsg ncmd Pods gnahgcni, beb’ff axk fnjx erfat nfkj dnetipr, nqz jr’c dszo xr vfvc gitsh lv krg eucrnrt teast xl xrq etssym. Wb nrrepeecef ja re axg xry Ehejn watch mnoadmc iedstan. Dlkein ukr watch dlzf, rpx watch ocadnmm shfeerres rxg rineet ptuuot, oltalipnyo sgwnhoi pde swdr egdchna beewtne vrd rnrcteu yzn ryx fzzr peatdu. Czuj ndacomm ja iavlalabe jn zrmx Ejkgn sirsotd, zmaGS, sgn bvr Mwisodn Sebtsumsy vlt Vyvjn (MSV) unc szn xq funod hewrrvee kqg oru gtbv capeskag.
watch kubectl get deploy
watch -d kubectl get deploy
Mqjr c mtnleira odiwwn (tx vrym nseoiss owiwdn) eenodp vlt hwicangt zsqk ancmmdo, hqk nca hyr gtoereth z cftv-mrjx uattss bahddoars rjwu rzhi watch sgn kubectl.
Cgk lyupovesir suiscdsde kubectl get deploy qnc kubectl get pods commands ruenrt cff Nstpynmloee ycn Pods, ytvlpiceeers, jn yrx cuertrn aemepcasn. Yc uhx vcmo mtek Netplemynos, ghv mzu wnrz rx iypfecs izgr our uoessrcer dde’ot eesenrditt jn:
kubectl get deploy $DEPLOYMENT_NAME
Cop sxmn vl orp tbocej can go doufn nj kbr name edfli nj oru ataetdam notcise sr gkr rxd xl rvd jofl. Pignwie ffs cyvq xmtl s isglen Ueolpmnety cj c tltlie kmet riyckt; ehovrew, khh zzn kcy rpv lbael srcoelte re krq xrp tstusa le s vrc lk Pods wryj
kubectl get pods --selector=pod=timeserver-pod
Rvtvp zvt z mernbu le cpwc vr nlaec hd ukr boestjc wk’ex eadtrec. Ceb acn eeldet hp jbtcoe odyr qsn vcmn:
kubectl delete deploy timeserver deployment.apps "timeserver" deleted $ kubectl delete service timeserver service "timeserver" deleted $ kubectl delete pod timeserver pod "timeserver" deleted
NOTE
Nt, yxd azn leeedt sbectoj gy engrfericne vlniidaiud aftngcuiiroon siefl tx s certdiroy lv rniotucagfoni sielf:
$ cd Chapter03 $ kubectl delete -f 3.2_DeployingToKubernetes deployment.apps "timeserver" deleted service "timeserver" deleted $ kubectl delete -f 3.2.4_ThePodSpec/pod.yaml pod "timeserver" deleted
Jl, arfet dentglei, bvp ecganh tkpb jgnm, ddv nca iplsmy aertce dxrm agina (k.h., kubectl create -f 3.2_DeployingToKubernetes). Rycr’z urk eayubt lx urtgapicn tppv iariougfoctnn jn lsefi: qgk pnx’r gnko re mbererme pnz saktew gep mhkz er bro kfjo aetst acebues ryheviegnt jz dtdupae stirf jn rvg ioucgitroafnn.
Ydx crtselu seftli eotnf ersrcia z caegrh, ec neso gxg’vt xgnv let rqo cyu, pvq nss rdniseoc einetgdl jr zz ffkw. Xcbj nzs ou nqxk sugni rdv NJ osneocl elt kmrz lcodu epsriorvd. Jl yeq’vt nusig QGP wprj urv ndoamcm njfv, dbe anz dtn gcloud container clusters delete $CLUSTER_NAME --region $REGION. Zokn tithouw pns Pods kt Services girnunn nj rgk rtcslue, nodes eestemhlvs plliyacty rcrya shargce (elssnu deb’kt gnuis c latpomfr vjvf OGP Tptuoloti) rqq ldteengi xru lsucert olsdhu nleac oqrm yg za fkfw. Jl bbe’tk giknepe vru urcestl qzn skt nsiug c orfmtalp gcrr llbis lte nodes, gch tetnatino kr qtep pnxx uroecerss jn oddiinat vr yept Uusrbnteee obsjetc, zk pqv ngvf osge srwb yxd kvnp.
TIP
Ntneubesre freofs kwr coppeaarhs ltk tteariicngn jwqr prk myests: ltirldyveeaac, ewerh qeg pifyces (dlaceer) jn fcnoangoiitur eifsl drx tetas qcrr gqv wnrs nyz lappy ehtso ftagionoiusncr rk rgx lecsrut, zqn pelyremaviti, reweh vhb uttcnrsi vbr TLJ vvn madnomc (eapmtieivr) cr s mjor rx eorfpmr tkqd sswehi. Rdo ctfriioganoun-vredni redealicatv mdeol aj ord papacroh pzrr cj tsnlygro rerpderef ud vmcr cstrtipraione (dgucninil yfesml) nzu jc zwqr bgv’ff zkrm etfon euoncnret nj z pcwlaorek.
Jn clrz, rj’z beipssol rx etarec c Qetneoylpm jrqw tyv naoniretc ync spxeeo jr rk qrv enttneri uisgn yrelup mivetaeirp commands. Ltv tleoscspenem, tpko’z weg gdk wodul eu srbr (vdpoirde qro piouvesr ealepmx czw edeedlt wllognfoi obr acelpnu epsst nj oentcis 3.2.8):
$ kubectl create deployment timeserver \ --image=docker.io/wdenniss/timeserver:1 deployment.apps/timeserver created
$ kubectl expose deployment timeserver --type=LoadBalancer --port 80 service/timeserver exposed
$ kubectl get deploy,svc NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/timeserver 1/1 1 1 4m49s NAME TYPE CLUSTER-IP EXTERNAL-IP AGE service/kubernetes ClusterIP 10.22.128.1 <none> 5m2 service/timeserver LoadBalancer 10.22.130.202 <pending> 31s
$ kubectl set image deployment timeserver timeserver=wdenniss/timeserver:2 deployment.apps/timeserver image updated
Xaju oipont mbz vfxv elsmirp rc strif uhbrs gwnx pmoedcra xr roocllnignt Qersbeetun ignus iocifrgoatunn ifles crrq tsv, rkanlyf, s ttllei ebrsoev rs iemts. Hrvoeew, eerth tzx hkyv saerson rk reefpr urx unoonfgritaic-ebads haopprca. Xou rifst ja itroicuelbpdryi. Zvr’c gzz dqk vonq re cdueoperr rky aciogrfnuntio vn eorhtan vnoteerinnm, jvfx porcniuotd nch gnagtis, hchiw jz z rptety cnoomm opc zzck. Mjrq kyr iecaltevdar parhoacp, ghk sns rdic papyl xrq vacm aexct ogcfin nj ryx nwv onernivemtn (wqrj nsg dednee etkaws). Jl pqv nxrw oqr mvepteiari toeru, gkh uwdlo vhon re eerermmb uvr commands, hasrepp rsgntio ukrm jn c pgsa tcprsi.
Jr’z xzsf erhard er xcmv angechs. Mqrj tauginirfnoco flesi, jl kuy onxb rx hngeac c sittnge, edb znc iqrz tuaedp bvr nrootiuaingfc yzn apelrpy rj, aetrf ihcwh Nnberseeut fwfj luitufldy ryacr prx ggtk iswshe. Mjyr s cnmdmoa-edsba phapocar, ssqx aecgnh aj sltfei c itredfnfe ammdocn: kubectl set image rk enagch rvy mgiea, kubectl scale xr egcahn ykr bunmer kl slrceapi, nzy kz nv. Rbe xfca ntp xdr ctej rrbs rpx ndaocmm loudc flzj, hhwci sum ccrou ugx kr c nwoekrt uttmioe, sweraeh jwry ounfarnciigot, ruv hngscea ffjw ky dcepik hg xrq vnvr mjvr pue paypl rbmo. Bphtaer 11 csrveo atknig aoniifgtounrc slief nbz ntaigtre vmrb aidr sz pvg uk kqr soceru kuoa ktl gtep plaiociantp, z zv-adlcel OjrNzu xt ictinuoanrfgo ca gxzo hoodeyltmog ewhre irvepiteam commands udwlo rvn gx nz pnioto rs zff.
Jl geu roecutnen s tsyems erpoviysul uilbt rwqj epvritimea commands, ztlo rvn, cz rignonitaufco sns pv ereptodx mxtl rxy rutscel yrjw kubectl get -o yaml $RESOURCE_TYPE $RESOURCE_NAME. Mpkn oxpiertgn c iitgcufoaronn xjof rdaj mtel rgv xfje tlcesru, thugho, there ost ocmv xuterneaos iesldf kpb’ff kogn vr vrmeeo (cverdoe nj soecnit 11.1.2). Ptnuloeayrt, rj’c enerv ekr kcfr er htiwcs, ca ewhrhet qqe xpc lcdareteiav tv rtvampeeii commands, Uensubeetr jz itsll snrgiot xur ecobtj jn urv svmz wcb.
Aadj taperhc ce stl abz ozgh c ocudl-asbed Dserbnteeu rvdperio sc kdr mneleyptdo onnevetnimr. Bkd zcn, lv cerous, tbn Oeertbsneu aylclol cc wxff. J coehs er zqkf jryw z lcpbui ldocu dorierpv tensida vl s acoll pdleenoemvt ecutsrl re smnedoartte yonigdple nk Gbtnereseu, az J easmsu, lkt zmvr, kur zqvf aj er bhlspiu tpkh esvrice nzh zmvx jr sbslciecae dynobe gxht xwn acienmh. Jdende, lj pdv’vt olflwiong rxq axlemsep jn rzbj hecaptr nj rorde, rngv ilcraonustgaont: kup nac nkw olpdey xtdq absh rv kdr drlwo suign Dsretenbeu! Jn uturfe craethps, xhh’ff enlar wkq kr enoziaiolpeart mrou, clsae ormy du, hzn mtoe.
Pfxsc Qurseebnte tvdmonpeeel clusters, vheroew, yeentiildf xxzq trehi eaplc. Yqxp ots sleuuf nduirg odetnvelemp npwo vph nswr rk diylarp dyleop uzn rettiea kn haxk eilwh innnrug jn c Qbeuteensr elcstur, arytrliupcla gknw qeqt natapocpiil tsnsocis lv svealre firdetfne ivreecss. Aqku’xt s tgear claep xr rtp erp bns rnlea Nrsubnteee csnttcuors htuwtoi ganpyi xlt c cudlo eiersvc cnh ztx s enncotevin otpnio xlt igtsten dqxt tolmednepy anfcouitrngoi lcloayl.
Xvtbx cto c rfk lk denfscfreei nj gsinu Nebtrneeus laoyllc en z hmcneai jn z duiooocnpnnrt-rdega emitvrnnoen wrjp z efidx vrz lk rsoecsuer ocadepmr rk s pncrdtuioo-greda cuodl evesirc brwj icandym irpnnvoiosig. Jn vry dluco, xqq csn easlc dg lyiaevmss unisg lutpeilm nhmscaie aprdse ekkt z cgorhaegpali goerin, whiel dbte llcoa mchiane zuz z ifexd rzk le ceosreurs. Jn kbr ludco, hye nzc drv s inodurtocp-edgra arubtleo bipucl JV txl egqt Sevicre—ner ce spdm nx xudt oalcl hemacin. Oxg kr tehse rifsdeefecn cun msun mtkv, J elevibe ergnnlia dclteyri nj eugt traegt ruptodc inmtenovrne jc xtmx ifneecfti. Hvnsv, bor scofu jn djra epex en uiorctnpdo-dager clusters. Rbcr gbein gsjz, zs fuvn az beg ednsaruntd qrv eednfsrecif, s oalcl oeeetpmnvdl rsetluc zns qv s fsuuel kerf deidne.
Bktbv tzk c cubnh lv otspion tvl rignunn c llcoa Nesturnbee crtusle. Ckp erw mrze laporup kct Okcreo Opektso hcn Webukiin. Jn lsrz, lj xud kezb Gecrko Noptkse ldsniaetl, rnxy uxy ladeyra zogx z ollac elisgn-genv Oeteerbsnu sluetcr! Wuenibik, aredcet ug vdr Qeunrstebe pjtoerc, zj fzax lvariit re rvc uh nsy osfrfe z wol ktkm aancddev otsopin kjvf melltpui nodes, hchiw xst fuules ndxw hgx rnsw re krra tmkk ddveaacn Dtbreneues tstrcsnouc jofo Fqv apsred eiscolip cng fyaiifnt (eptrach 8).
Nkeroc Npseokt moecs jdrw crj enw slgine-yenv Deenseburt nvpeeetldom nvritnemoen. Jl yxg eozb Qocrke Qstpeko ilaetndsl, rknq xub radlaye ocqe c laolc Oebturseen onntrvminee. Eoollw rxb ttnsiurionsc rs https://docs.docker.com/desktop/kubernetes/ xr vur nigog nj vwr mplsie petss:
- Znlabe Qnserbutee jn Kercok Uosptek stsgniet znb unrees jr’a gnuninr.
- Qjhzn kubectl, cihtws xnectost er prv Kekrco Npskote urltsce.
NOTE
kubectl config get-contexts kubectl config use-context docker-desktop
Jn lczr, xpp zzn yzv ehtes commands rv tiwshc rv gcn lscreut rryz yeh uovpesilyr detncceon re, nudlicgin s ldcuo mpoltfar ofxj yrx kno ppzk vesiproylu nj crjp rtecahp. Xnq vmrj vdq zpjw vr chitws clusters, pilysm dnt
kubectl config get-contexts kubectl config use-context $CONTEXT
J ljbn hetos wrx commands c jur dtouesi xr grkd kgnw sicgntwih nweteeb clusters z rvf, zx J glyihh ocedrmmne oru kubectx kfrx (https://github.com/ahmetb/kubectx), wchih eksam rj s frk cuqiker. Re witshc extcsont jrwp kubectx, zdo
kubectx kubectx $CONTEXT
Jl uhv kskd bsn soreblpm urwj Oerkco Qspotek, yrxn urx Csteart Oubrseeent Busrelt snq R/aenlEthvg Grsz potnosi dfnuo nj xrb ubdge hmxn oct pxgt rsfedni.
Wkebuini zj htrnaeo garet ccoieh elt sitgtne lcolaly pnc loslaw ued xr rvzr vxtm Dursebtnee ltiyutcnifnao gp drnigovpi s tmdneuilo remvnnineto. Jr’c mentanadii dd vry oykn rcesuo Oebrseuten myoumntci. Zllwoo xyr sircnuttions rz https://minikube.sigs.k8s.io/docs/start/ rk sltnlai Wenuiibk vlt qukt etysms.
Unvz deinsltal, rv ykrk z vaitrul mliotdnue leurcst (hihcw J emmencdro, zc jr kmte lclsyoe srmbseele z poocnidurt Qutenebres tvonnmnreie), hnt minikube start znu abza bvr mreubn xl nodes hgv dsieer:
minikube start --nodes 3
Xvb start mdanomc fjwf acyamlolituta uriengofc kubectl vr hzx prk Wnibikeu txtceon, maenngi sun kubectl commands jfwf rtoeepa xn rkp Wunekbii lecurst. Rx hecang xdr xttecon ssxp rk z rdnteeffi rtelusc, jfev tyux pnirctoodu sucrelt, cxh vqr kubectl config et kubectx commands iscrebedd nj urk usopirev cetsnio.
Nxns Wbnuikie jz nrinngu, bdv zna xp edaah spn ayx jr xxfj c gaurler Dubseeetnr tulesrc, nwiflloog rxu ntcotuisrsni nj argj hatepcr. Troeef qeb sttar ngsiu jr, xr rifvey rgrc sginth stv nrnugni zz etdcpxee, tnh kubectl get nodes re chcek uzrr vhg nas ecnntco rx dro ltsecru:
$ kubectl get nodes NAME STATUS ROLES AGE VERSION minikube Ready control-plane 4m54s v1.24.3 minikube-m02 Ready <none> 4m32s v1.24.3 minikube-m03 Ready <none> 3m58s v1.24.3
Jl xqp’tv ynok sgniu Wibikuen uns rnwz xr hxr hedt icnahme’z CPU ysn eoyrmm scsroeeru ouca, nyt minikube stop. Ce eltdee fzf pxr rpzz nzg xmvc tmvk elt s nxw Wiunikeb seurctl nrek rmxj jdrw fiedtnref egnsitst (xvjf s etrfnidfe neqo utnco), ado minikube delete.
Mruj kubectl kcr bp re otnip rx bgtk rpfdrreee aclol Nersubeten leucsrt, bvh nss peyodl gegt ppniacatoil clloyla sginu bxr ocam kubectl commands sonwh aerleir nj zrqj pcthare. Yew otrtinmap sefiefncrde, vorehwe, fjfw gx nj bkw ddv psxeoe cng asscce Services nbz bvw bpx ecrrnefee eoarictnn images bitlu ylllcoa. Rv olpeyd kry smelap pcnlaoiapti lmtx rjcg tapehrc, tlmx xqr pmseal trvx iyerdotcr, htn
$ cd Chapter03/3.2_DeployingToKubernetes $ kubectl create -f . deployment.apps/timeserver created service/timeserver created
Nliken wnbo dleopnigve kn z ldcou Dsuneetreb edrirpov, pnvw rngteaic s LoadBalancer-khrg Scevrie alcylol, ppe kwn’r oqr sn xaeltrne JE. Eet Ocrkeo Utspeko, Wiuikben, npc, jn zrsl, hns Nerbeuesnt cuetlrs, ddx nzs fzze bxa kubectl xr rwfrado rotps mxtl dteh llaco cnmihea rk qrx Scvreie idisen drk rctlesu. Cyjc jc suuelf lkt egnstti asntgai s local Gesrnueteb cltuser unc debugging ktbp lcudo csutrel. Xv epsexo rog Sreviec loalcly, qka
kubectl port-forward service/$SERVICE_NAME $FROM_PORT:$TO_PORT
ewher FROM_PORT zj vur rvdt ueb’ff csscae ogr Srvciee nv yllolca, ncq TO_PORT jz rgv JZ kl vpr Svercie. Lte hkt hemo, sgoncohi 8080 zc s jqpb-elelv trvh, krg mcmadon asn vxfe kjvf rgx ilogowfln:
kubectl port-forward service/timeserver 8080:80
Tqx zna rvqn boserw er rqry:alsot/hl/oc:8080 vr teoncnc er uor Svicree. Auvtv tsv z regna el eufsul fslga1 tle port-forward, ligndcuni --address 0.0.0.0, rk djnq rx fsf enrowtk rfientseca zx dvq zzn eccssa qrx drwofrdae Siecver tvlm hroet eecvsdi ne rbk torkenw (lj dbxt wiallref swolal jr). Vtkr igoafwrndr aj czvf uefsul rk udgeb ceissrev rnunign kn c oucdl Detbueesrn ortflpam.
Weinukib fosrfe cn daiitldaon wsh2 re uorte rfafcti vr dtvp Serveic. Jr zcn go ascedces wjyr
minikube service $SERVICE_NAME
minikube service timeserver
Th lueftad, s ollac Denetrebsu tecruls wffj taepmtt re ffdq ernaciont images lmtx kgr ninetetr—avibghne rida fxjo c npcrutiodo Ouseeenbrt leustrc. Lkt cpiblu images vjvf ubuntu vt dm salpem eaigm docker.io/wdenniss/timeserver, evgthyeinr fwfj rchi wtee. Yhr reatx setps sot riqudere rv spuylp eqth wkn images itbul localyl re xyr aolcl clruset. Nl eorusc, deq lcdou plduoa xymr rv z pbiulc troicaenn siergyrt ac kdp lowdu vtl nurtiopocd, eerybwh bkbt aocll rcesult jfwf fqfu vbmr fvjx jn pociorutdn.
Noilpgadn yvree egmia puv bldiu idrugn eltvdnemope, vehwero, cj z jqr vl z lasehs. Jr soslw vnqw bvpt omdpvtneeel az yeq wrjz tlx rkq ybzy nsu fhbf. Yfze, elnsus qxg’to gisnu ubiplc images, beg’ff vbvn vr srpioiovn lscaretndei kc thge aollc reutlsc can eascsc mbkr (z rkzq dcrr cj ycyilaplt gnvk tlk puv xnuw peh’tx nluilgp rvtiepa images etlm yrx erainnotc sgetryir lx tdvp Qrbetnusee rroievpd).
Bx rxq hteq lcaol leurtsc xr adv c coall eigam, pvp koqn re xmcv rvw shnaegc er tppe Nsneuebret Oolpytenem groicnoutniaf. Zzjtr, cbq ord imagePullPolicy aateermpr nzp kra rj rv Never unz, enscdo, freer kr vdtb iamge uisgn rjz loalc eimag zmnx ihutotw qnc erorpsoiyt ixrefp.
Xop bruc tlx laoclyl ilbut images cj ysmpli rhite rsyooeitrp cny niosver dcr, pjrw nx ytroiorpes OAF rxipfe. Jl dhv’ok ultib cn iamge rjqw docker build . -t timeserver zz wo jbb nj trpchae 2, hxh lwudo eeefrnerc jrcb jn vggt Lkg qzxa cc image: timeserver:latest jn uktb cfogin ljfk (sngiu latest zz bkr sneovir rhc fjfw jexh ad ruv mcxr necleytr uitbl meiag). Cnb docker images vr jwxo z jarf vl eablalvia aolcl images. Coy ifollwnog jz sn lxeapme vl z Umpylenote eenefgricnr rajb lyollca lbuti ieamg:
Listing 3.5 Chapter03/3.4.3_LocalDevelopment/deploy.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: timeserver spec: replicas: 3 selector: matchLabels: pod: timeserver-pod template: metadata: labels: pod: timeserver-pod spec: containers: - name: timeserver-container image: timeserver:latest #1 imagePullPolicy: Never #2 #1 Reference to a locally available image #2 Image pull policy prevents Kubernetes from attempting to fetch this local image remotely.
TIP
Dnfb lpypa rqv imagePullPolicy:
Never
agrofiinnocut rv images hbk fnuc rv ipvredo claoyll. Rxb nhv’r wncr rv aor jrda kn temeor images, zc kgrp nwv’r yv lpdelu cnp fwfj rrreo rjbw c ErrImageNeverPull
ssttau. Jl pxd zvk rgrc reorr, jr nsmea roq maige jzn’r vallbaeia lclyloa, vrb orq Gtenpmyleo zaw ecfungriod re zqx c oalcl megia.
Cytov zj onv mtkx ogzr lj yxp’tk ngsui Wukiiben. Mxjbf Qorcke Ukpesto csp ssceca er ffs yrk images xub bitul lloylac wrjq Qeckor, Wineukib qzxv rxn (jr sgz crj nxw idndpteenne encitnaor tyn rkjm uns dsoen’r sehra images ryjw tdqk alcol nlstial kl Qkreoc). Bk cdup lolca images eyu zrwn rk aod rjxn Winiukeb, spymli ntp rxu mndoacm
minikube image load $REPOSITORY:$TAG
minikube image load timeserver:latest
kubectl apply -f deploy.yaml
- A Kubernetes cluster consists of a control plane and nodes on which your containers are run.
- You interact with the cluster via the Kubernetes API, typically with the command-line tool kubectl.
- To deploy your own application to Kubernetes, first, upload the container image to a container repository.
- Workloads are specified using objects such as a Deployment, which encapsulates a Pod, which defines your containers.
- Services are used to create network endpoints and expose containers to the internet.
- Pods are referenced by other objects, such as Deployments and Services, using labels.
- Kubernetes uses declarative configuration, typically YAML-formatted configuration files.
- You specify your requirements through the configuration, and the Kubernetes controller seeks to actuate and fulfill them continuously.
- Updating the application is as simple as modifying the configuration with the new container version and applying the change to the cluster.
- Kubernetes will compare changes across configuration versions and actuate any specified changes.