{"id":897,"date":"2019-10-29T16:39:20","date_gmt":"2019-10-29T16:39:20","guid":{"rendered":"https:\/\/thinkcolorful.org\/?p=897"},"modified":"2024-12-13T19:41:10","modified_gmt":"2024-12-13T19:41:10","slug":"cloud-native-with-node-js-docker-and-kubernetes","status":"publish","type":"post","link":"https:\/\/thinkcolorful.org\/?p=897","title":{"rendered":"Cloud Native with Node.js, Docker and Kubernetes"},"content":{"rendered":"\n<p>I decided to get my hands dirty and use a bunch of technologies I&#8217;ve had some exposure to but haven&#8217;t tried to setup personally.  I began by creating a website with <a href=\"https:\/\/nodejs.org\/en\/\">Node.js<\/a> and the <a href=\"https:\/\/expressjs.com\/\">Express<\/a> framework for the Node Meetup group I co-organize. It&#8217;s a simple website which explains what the group is about, has an events calendar, provides a feedback page and showcases some of the member&#8217;s work.  <a href=\"https:\/\/thinkcolorful.org:9999\/\">Here is the development site<\/a> up and running on my server and here is the<a href=\"https:\/\/gitlab.com\/ephemeralwaves\/node-website\"> gitlab repository where the code lives<\/a>.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>From there I created a docker image by going to <a href=\"https:\/\/www.cloudnativejs.io\/\">CloudNativejs.io <\/a>and going to their <a href=\"https:\/\/github.com\/CloudNativeJS\/docker\">Docker git repo<\/a> to pull down the Dockerfiles.  I tried building the various Dockerfiles to see how each of them worked and used the Dockerfile-run template since it was the leanest option. From there I ran it to check that it worked. I then tagged it to prepare it for publishing and <a href=\"https:\/\/hub.docker.com\/r\/ephemeralwaves\/nodepghserver\">published it on dockerhub<\/a>. Here are the commands I used:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}\">#build\ndocker build -t nodepghserver-run -f Dockerfile-run .\n#verify that it's a smaller size!\ndocker images\n#run\ndocker run -i -p 3000:3000 -t nodepghserver-run\n#stopped it with ctrl+c\n\n#Tag it\ndocker tag nodepghserver-run nodeserver:1.0.0\n\n#Publish\ndocker login\n#retag image so it lives in your username namespace\ndocker tag nodepghserver-run ephemeralwaves\/nodeserver:1.0.0\n#push\ndocker push ephemeralwaves\/nodepghserver<\/pre><\/div>\n\n\n\n<p>The next part of my journey involved using Helm and Kubernetes. I installed <a href=\"https:\/\/microk8s.io\/docs\/\">Microk8s<\/a> by Canonical which was a snap (no pun intended!) and enabled Helm. I got a template Helm chart from  <a href=\"https:\/\/www.cloudnativejs.io\/\">CloudNativejs.io<\/a>&#8216;s <a href=\"https:\/\/github.com\/CloudNativeJS\/helm\">Helm repo<\/a>. I got stuck here for about an hour until I realized that the chart was outdated and a pull request was pending that updated the charts (it has since been updated!). <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}\">#install micro8s from https:\/\/microk8s.io\/#quick-start \nsudo snap install microk8s --classic\nsudo microk8s.enable helm\nsudo microk8s.helm init\n\n#get and put helm chart into project folder\ngit clone https:\/\/github.com\/CloudNativeJS\/helm\nmv chart\/ myappfolder\/\n\n#change name of repo in values.yaml\n\n#then go into repo and install\/deploy\nsudo microk8s.helm install --name nodepghserver chart\/nodeserver\n#check with\nsudo microk8s.helm status nodepghserver\n#open browser to yourLocalIPAddress:Port listed in helm status<\/pre><\/div>\n\n\n\n<p>For seamless upgrades and rollbacks just use the helm rollback and upgrade commands so no up time is lost.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;Shell&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;shell&quot;}\">#seamless upgrade so no downtime!\nsudo microk8s.helm upgrade nodepghserver chart\/nodeserver\n\n#if you need to rollback\n#check history\nsudo microk8s.helm history nodepghserver\n#rolling back to revision 1\nsudo microk8s.helm rollback nodepghserver 1\n<\/pre><\/div>\n\n\n\n<p>More to come about<a href=\"https:\/\/github.com\/CloudNativeJS\/appmetrics-prometheus\"> Prometheus integration<\/a> and <a href=\"https:\/\/github.com\/CloudNativeJS\/cloud-health-connect\">health checks<\/a>!<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I decided to get my hands dirty and use a bunch of technologies I&#8217;ve had some exposure to but&#46;&#46;&#46;<\/p>\n","protected":false},"author":2,"featured_media":1326,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[214,6,10,218],"tags":[],"class_list":["post-897","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","category-organization","category-programming","category-sre-devops"],"_links":{"self":[{"href":"https:\/\/thinkcolorful.org\/index.php?rest_route=\/wp\/v2\/posts\/897","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thinkcolorful.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thinkcolorful.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thinkcolorful.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/thinkcolorful.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=897"}],"version-history":[{"count":18,"href":"https:\/\/thinkcolorful.org\/index.php?rest_route=\/wp\/v2\/posts\/897\/revisions"}],"predecessor-version":[{"id":1066,"href":"https:\/\/thinkcolorful.org\/index.php?rest_route=\/wp\/v2\/posts\/897\/revisions\/1066"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/thinkcolorful.org\/index.php?rest_route=\/wp\/v2\/media\/1326"}],"wp:attachment":[{"href":"https:\/\/thinkcolorful.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=897"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thinkcolorful.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=897"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thinkcolorful.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=897"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}