Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Set Up a CI/CD Pipeline with Kubernetes Part 1: Overview

#1
Set Up a CI/CD Pipeline with Kubernetes Part 1: Overview

<div style="margin: 5px 5% 10px 5%;"><img src="http://www.sickgaming.net/blog/wp-content/uploads/2018/10/set-up-a-ci-cd-pipeline-with-kubernetes-part-1-overview.png" width="256" height="256" title="" alt="" /></div><div><h3><span><span>What’s New? </span></span></h3>
<p><span><span>We’ve updated the four parts of this blog series and versioned the code along with it to include the following new technology components. </span></span></p>
<ul>
<li>
<p><span><span>Jenkins Plugin Kubernetes Continuous Deploy has  been added to deployments. </span><a href="https://plugins.jenkins.io/kubernetes-cd"><span>https://plugins.jenkins.io/kubernetes-cd</span></a></span></p>
</li>
<li>
<p><span><span>Kubernetes RBAC and serviceaccounts are being used by applications to interact with the cluster. </span></span></p>
</li>
<li>
<p><span><span>We are now introducing and using Helm for a deployment (specifically for the deployment of the etcd-operator in part 3)</span></span></p>
</li>
<li>
<p><span><span>All versions of the main tools and technologies have been upgraded and locked</span></span></p>
</li>
<li>
<p><span><span>Fixed bugs, refactored K8s manifests and refactored applications’ code</span></span></p>
</li>
<li>
<p><span><span>We are now providing Dockerfile specs for socat registry and Jenkins</span></span></p>
</li>
<li>
<p><span><span>We’ve improved all instructions in the blog post and included a number of informational text boxes</span></span></p>
</li>
</ul>
<p><span><span>The software industry is rapidly seeing the value of using containers as a way to ease development, deployment, and environment orchestration for app developers. Large-scale and highly-elastic applications that are built in containers definitely have their benefits, but managing the environment can be daunting. This is where an orchestration tool like Kubernetes really shines. </span></span></p>
<p><span><span>Kubernetes is a platform-agnostic container orchestration tool created by Google and heavily supported by the open source community as a project of the Cloud Native Computing Foundation. It allows you to spin up a number of container instances and manage them for scaling and fault tolerance. It also handles a wide range of management activities that would otherwise require separate solutions or custom code, including request routing, container discovery, health checking, and rolling updates.</span></span></p>
<p><a href="http://kenzan.com/?ref=linux">Kenzan</a><span><span> is a services company that specializes in building applications at scale. We’ve seen cloud technology evolve over the last decade, designing microservice-based applications around the Netflix OSS stack, and more recently implementing projects using the flexibility of  container technology. While each implementation is unique, we’ve found the combination of microservices, Kubernetes, and Continuous Delivery pipelines to be very powerful.</span></span></p>
<h2><span><span>Crossword Puzzles, Kubernetes, and CI/CD </span></span></h2>
<p><span><span>This article is the first in a series of four blog posts. Our goal is to show how to set up a fully-containerized application stack in Kubernetes with a simple CI/CD pipeline to manage the deployments. </span></span></p>
<p><span><span>We’ll describe the setup and deployment of an application we created especially for this series. It’s called the Kr8sswordz Puzzle, and working with it will help you link together some key Kubernetes and CI/CD concepts. The application will start simple enough, then as we progress we will introduce components that demonstrate a full application stack, as well as a CI/CD pipeline to help manage that stack, all running as containers on Kubernetes. Check out the architecture diagram below to see what you’ll be building.</span></span></p>
<p><em>Read all the articles in the series:</em></p>
<p><span><span>The completed application will show the power and ease with which Kubernetes manages both apps and infrastructure, creating a sandbox where you can build, deploy, and spin up many instances under load. </span></span><span><span> </span></span></p>
<h2><span><span>Get Kubernetes up and Running </span></span></h2>
<p><span><span>The first step in building our Kr8sswordz Puzzle application is to set up Kubernetes and get comfortable with running containers in a pod. We’ll install several tools explained along the way: Docker, Minikube, and Kubectl.</span></span><span><span> </span></span></p>
<div>
<table>
<tbody>
<tr>
<td><span><img alt="9m-m-dyeYpMNvBD5Cxr3_GzLX-MrMKWZ9A9MGR-a" height="20" src="http://www.sickgaming.net/blog/wp-content/uploads/2018/10/set-up-a-ci-cd-pipeline-with-kubernetes-part-1-overview.png" width="20" /></span></td>
<td>
<p><span><span>This tutorial only runs locally in Minikube and will not work on the cloud. You’ll need a computer running an up-to-date version of Linux or macOS. Optimally, it should have 16 GB of RAM. Minimally, it should have 8 GB of RAM. For best performance, reboot your computer and keep the number of running apps to a minimum. </span></span></p>
</td>
</tr>
</tbody>
</table>
</div>
<h2><span><span>Install Docker</span></span></h2>
<p><span><span>Docker is one of the most widely used container technologies and works directly with Kubernetes. </span></span></p>
<h3><strong><span><span>Install Docker on Linux</span></span></strong></h3>
<p><span><span>To quickly install Docker on Ubuntu 16.04 or higher, open a terminal and enter the following commands (see the </span><a href="https://docs.docker.com/engine/installation/"><span>Linux installation instructions</span></a><span> for other distributions):</span></span></p>
<pre>
<span><span>sudo apt-get update</span></span>
<span><span>curl -fsSL https://get.docker.com/ | s</span></span>
</pre>
<p><span><span>After installation, </span><a href="https://docs.docker.com/engine/installation/linux/linux-postinstall/#/manage-docker-as-a-non-root-user"><span>create a Docker group</span></a><span> so you can run Docker commands as a non-root user (you’ll need to log out and then log back in after running this command):</span></span></p>
<pre>
<span><span>sudo usermod -aG docker $USER</span></span>
</pre>
<p><span><span>When you’re all done, make sure Docker is running:</span></span></p>
<pre>
<span><span>sudo service docker start</span></span>
</pre>
<h3><strong><span><span>Install Docker on macOS</span></span></strong></h3>
<p><span><span>Download </span><a href="https://docs.docker.com/docker-for-mac/install/#download-docker-for-mac"><span>Docker for Mac (stable)</span></a><span> and follow the installation instructions. To launch Docker, double-click the </span><span>Docker</span><span> icon in the Applications folder. Once it’s running, you’ll see a whale icon in the menu bar.</span></span></p>
<p><img alt="2wFuUBKImxVs4uoJ8wc-giTDD_vtnEI5R2GXzlRp" src="http://www.sickgaming.net/blog/wp-content/uploads/2018/10/set-up-a-ci-cd-pipeline-with-kubernetes-part-1-overview-1.png" /></p>
<h3><strong><span><span>Try Some Docker Commands</span></span></strong></h3>
<p><span><span>You can test out Docker by opening a terminal window and entering the following commands: </span></span><span><span> </span></span></p>
<pre>
<span><span># Display the Docker version</span></span> <span><span>docker version</span></span> <span><span># Pull and run the Hello-World image from Docker Hub</span></span> <span><span>docker run hello-world</span></span> <span><span># Pull and run the Busybox image from Docker Hub</span></span> <span><span>docker run busybox echo "hello, you've run busybox"</span></span> <span><span># View a list of containers that have run</span></span> <span><span>docker ps -a</span></span>
</pre>
<div>
<table>
<tbody>
<tr>
<td>
<p><span><span><img alt="9m-m-dyeYpMNvBD5Cxr3_GzLX-MrMKWZ9A9MGR-a" height="20" src="http://www.sickgaming.net/blog/wp-content/uploads/2018/10/set-up-a-ci-cd-pipeline-with-kubernetes-part-1-overview.png" width="20" /></span></span></p>
</td>
<td>
<p><span><a href="https://docs.docker.com/engine/getstarted/step_two/"><span>Images</span></a><span> are specs that define all the files and resources needed for a container to run. Images are defined in a </span><a href="https://docs.docker.com/get-started/part2/#define-a-container-with-dockerfile"><span>DockerFile</span></a><span>, and built and stored in a repository. Many OSS images are publically available on </span><a href="https://hub.docker.com/"><span>Docker Hub</span></a><span>, a web repository for Docker images. Later we will setup a private image repository for our own images.</span></span></p>
</td>
</tr>
</tbody>
</table>
</div>
<h2><span><span>Install Minikube and Kubectl</span></span></h2>
<p><span><strong><span>Minikube</span></strong><span> is a single-node Kubernetes cluster that makes it easy to run Kubernetes locally on your computer. We’ll use Minikube as the primary Kubernetes cluster to run our application on. </span><strong><span>Kubectl</span></strong><span><strong> </strong>is a command line interface (CLI) for Kubernetes and the way we will interface with our cluster. (For details, check out </span><a href="http://kubernetes.io/docs/getting-started-guides/minikube/"><span>Running Kubernetes Locally via Minikube</span></a><span>.)</span></span></p>
<h3><span><span>Install Virtual Box</span></span></h3>
<p><span><span>Download and install the </span><a href="https://www.virtualbox.org/wiki/Downloads"><span>latest version of VirtualBox</span></a><span> for your operating system. VirtualBox lets Minikube run a Kubernetes node on a virtual machine (VM)</span></span></p>
<h3><span><span>Install Minikube</span></span></h3>
<p><span><span>Head over to the </span><a href="https://github.com/kubernetes/minikube/releases"><span>Minikube releases page</span></a><span> and install the latest version of Minikube using the recommended method for your operating system. This will set up our Kubernetes node.</span></span></p>
<h3><span><span>Install Kubectl</span></span></h3>
<p><span><span>The last piece of the puzzle is to install kubectl so we can talk to our Kubernetes node. Use the commands below, or go to the </span><a href="https://kubernetes.io/docs/tasks/kubectl/install/"><span>kubectl install page</span></a><span>. </span></span></p>
<p><span><span>On </span><strong><span>Linux</span></strong><span>, install kubectl using the following command: </span></span></p>
<pre>
<span><span>curl -LO
https://storage.googleapis.com/kubernete...e/release/$(curl -s https://storage.googleapis.com/kubernete...64/kubectl &amp;&amp; chmod +x kubectl &amp;&amp; sudo mv kubectl /usr/local/bin/</span></span>
</pre>
<p><span><span>On </span><strong><span>macOS</span></strong><span>, install kubectl using the following command:</span></span></p>
<pre>
curl -LO https://storage.googleapis.com/kubernete...e/release/$(curl -s https://storage.googleapis.com/kubernete...64/kubectl &amp;&amp; chmod +x kubectl &amp;&amp; sudo mv kubectl /usr/local/bin/
</pre>
<h3><span><span>Install Helm</span></span></h3>
<p><span><a href="https://helm.sh/"><span>Helm</span></a><span> is a package manager for Kubernetes. It allows you to </span><span>deploy Helm Charts (or packages) onto a K8s cluster with all the resources and dependencies needed for the application. We will use it a bit later in Part 3, and highlight how powerful Helm charts are. </span></span></p>
<p><span><span>On </span><strong><span>Linux</span></strong><span> or </span><span><strong>macOS</strong>, </span><span>install Helm with the following command.</span></span><span><span> </span></span></p>
<pre>
<span><span>curl https://raw.githubusercontent.com/kubern...cripts/get &gt; get_helm.sh; chmod 700 get_helm.sh; ./get_helm.sh</span></span>
</pre>
<h3><span><span>Fork the Git Repo</span></span></h3>
<p><span><span>Now it’s time to make your own copy of the Kubernetes CI/CD repository on Github.</span></span></p>
<p>1. Install Git on your computer if you don’t have it already.</p>
<p><span><span>On </span><strong><span>Linux</span></strong><span><strong>,</strong> use the following command:</span></span></p>
<pre>
<span><span>sudo apt-get install git</span></span>
</pre>
<p><span><span>On </span><strong><span>macOS</span></strong><span><strong>,</strong> download and run the </span><a href="https://git-scm.com/downloads"><span>macOS installer for Git</span></a><span>. To install, first double-click the .dmg file to open the disk image. Right-click the .pkg file and click </span><span>Open</span><span>, and then click </span><span>Open</span><span> again to start the installation.</span></span></p>
<p><span><span>2. Fork Kenzan’s </span><a href="https://github.com/kenzanlabs/kubernetes-ci-cd"><span>Kubernetes CI/CD repository</span></a><span> on Github. This has all the containers and other goodies for our Kr8sswordz Puzzle application, and you’ll want to fork it as you’ll later be modifying some of the code. </span></span></p>
<p><span><span>   a. <a href="https://github.com/join">Sign up</a> if you don’t yet have an account on Github.  </span></span></p>
<p><span><span>   b. On the </span><a href="https://github.com/kenzanlabs/kubernetes-ci-cd"><span>Kubernetes CI/CD repository</span></a><span> on Github, click the </span><span>Fork</span><span> button in the upper right and follow the instructions.</span></span></p>
<p><img alt="VWmK6NaGcXD3TPZL6YRk_XPNZ8lqloN6of6yIUe7" height="136" src="http://www.sickgaming.net/blog/wp-content/uploads/2018/10/set-up-a-ci-cd-pipeline-with-kubernetes-part-1-overview-2.png" width="418" /></p>
<p><span><span>  c. </span></span><span><span>Within a chosen directory, clone your newly forked repository. </span></span></p>
<pre>
<span> <span>git clone https://github.com/</span><span>YOURUSER...pan></span>
</pre>
<p> d. <span><span>Change directories into the newly cloned repo.</span></span></p>
<h3><span><span>Clear out Minikube</span></span></h3>
<p><span><span>Let’s get rid of any leftovers from previous experiments you might have conducted with Minikube. Enter the following terminal command:</span></span></p>
<pre>
<span><span><span><span>minikube stop; minikube delete; sudo rm -rf ~/.minikube; sudo rm -rf ~/.kub</span></span></span></span>
</pre>
<div>
<table>
<tbody>
<tr>
<td>
<p><span><span><img alt="9m-m-dyeYpMNvBD5Cxr3_GzLX-MrMKWZ9A9MGR-a" height="20" src="http://www.sickgaming.net/blog/wp-content/uploads/2018/10/set-up-a-ci-cd-pipeline-with-kubernetes-part-1-overview.png" width="20" /></span></span></p>
</td>
<td>
<p><span><span>This command will clear out any other Kubernetes contexts you’ve previously setup on your machine locally, so be careful. If you want to keep your previous contexts, avoid the last command which deletes the </span><span>~/.kube</span><span> folder. </span></span></p>
</td>
</tr>
</tbody>
</table>
</div>
<h2><span><span>Run a Test Pod</span></span></h2>
<p><span><span>Now we’re ready to test out Minikube by running a </span><strong><span>Pod</span></strong><span> based on a public image on Docker Hub</span></span><span><span>. </span></span></p>
<div>
<table>
<tbody>
<tr>
<td>
<p><span><span><img alt="9m-m-dyeYpMNvBD5Cxr3_GzLX-MrMKWZ9A9MGR-a" height="20" src="http://www.sickgaming.net/blog/wp-content/uploads/2018/10/set-up-a-ci-cd-pipeline-with-kubernetes-part-1-overview.png" width="20" /></span></span></p>
</td>
<td>
<p><span><span>A </span><a href="https://kubernetes.io/docs/concepts/workloads/pods/pod/"><span>Pod</span></a><span> is Kubernetes’ resiliency wrapper for containers, allowing you to horizontally scale replicas. </span></span></p>
</td>
</tr>
</tbody>
</table>
</div>
<p><span><span>1. Start up the Kubernetes cluster with Minikube, giving it some extra resources.</span></span></p>
<pre>
<span><span>minikube start --memory 8000 --cpus 2 --kubernetes-version v1.6.0</span></span>
</pre>
<div>
<table>
<tbody>
<tr>
<td>
<p><span><span><img alt="9m-m-dyeYpMNvBD5Cxr3_GzLX-MrMKWZ9A9MGR-a" height="20" src="http://www.sickgaming.net/blog/wp-content/uploads/2018/10/set-up-a-ci-cd-pipeline-with-kubernetes-part-1-overview.png" width="20" /></span></span></p>
</td>
<td>
<p><span><span>If your computer does not have 16 GB of RAM, we suggest giving Minikube less RAM in the command above. Set the memory to a minimum of 4 GB rather than 8 GB. </span></span></p>
</td>
</tr>
</tbody>
</table>
</div>
<p><span><span>2. Enable the Minikube add-ons <a href="https://github.com/kubernetes/heapster">Heapster</a> and <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/">Ingress</a>.</span></span></p>
<pre>
<span><span>minikube addons enable heapster; minikube addons enable ingress</span></span></pre>
<p>Inspect the pods in the cluster. You should see the add-ons heapster, influxdb-grafana, and nginx-ingress-controller.</p>
<pre>
kubectl get pods --all-namespaces
</pre>
<p><span><span>3. View the Minikube Dashboard in your default web browser. Minikube Dashboard is a UI for managing deployments. You may have to refresh the web browser if you don’t see the dashboard right away. </span></span></p>
<pre>
<span><span>minikube service kubernetes-dashboard --namespace kube-system</span></span>
</pre>
<p><span><span>4. Deploy the public nginx image from DockerHub into a pod. Nginx is an open source web server that will automatically download from Docker Hub if it’s not available locally. </span></span></p>
<pre>
<span><span>kubectl run nginx --image nginx --port 80</span></span>
</pre>
<p><span><span>After running the command, you should be able to see nginx under Deployments in the Minikube Dashboard with Heapster graphs. (If you don’t see the graphs, just wait a few minutes.)</span></span></p>
<p><img alt="taZzJW57y2HD12JINuNJeuo-9LrkFMLjQEfcU0G5" src="http://www.sickgaming.net/blog/wp-content/uploads/2018/10/set-up-a-ci-cd-pipeline-with-kubernetes-part-1-overview-3.png" /></p>
<div>
<table>
<tbody>
<tr>
<td>
<p><span><span><img alt="9m-m-dyeYpMNvBD5Cxr3_GzLX-MrMKWZ9A9MGR-a" height="20" src="http://www.sickgaming.net/blog/wp-content/uploads/2018/10/set-up-a-ci-cd-pipeline-with-kubernetes-part-1-overview.png" width="20" /></span></span></p>
</td>
<td>
<p><span><span>A </span><a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/"><span>Kubernetes Deployment</span></a><span> is a declarative way of creating, maintaining and updating a specific set of Pods or objects. It defines an ideal state so K8s knows how to manage the Pods. </span></span></p>
</td>
</tr>
</tbody>
</table>
</div>
<p><span><span>5. Create a K8s service for deployment. This will expose the nginx pod so you can access it with a web browser.</span></span></p>
<pre>
<span><span>kubectl expose deployment nginx --type NodePort --port 80</span></span>
</pre>
<p><span><span>6. </span></span><span><span>The following command will launch a web browser to test the service. The nginx welcome page displays, which means the service is up and running. Nice work!</span></span></p>
<pre>
<span><span>minikube service nginx</span></span>
</pre>
<p><span><span><img alt="5Mm8CSeIyO1clhqVqD4v-j4hZGWjUMPGCI1MA36E" height="228" src="https://lh4.googleusercontent.com/5Mm8CSeIyO1clhqVqD4v-j4hZGWjUMPGCI1MA36EXVOjM0ebRbUTHtqIcpc_e2xPLHwaD2I9-YdY76s7BZHTk4XfN3zedNzHy1o0QCjhT0Qhg2fYVzExGiJYLmoaQmWFqRe7F8Lm" width="624" /></span></span></p>
<p><span><span>7. Delete the nginx deployment and service you created.</span></span></p>
<pre>
<span><span>kubectl delete service nginx</span>
<span>kubectl delete deployment nginx</span></span>
</pre>
<h2><span><span>Create a Local Image Registry</span></span></h2>
<p><span><span>We previously ran a public image from Docker Hub. While Docker Hub is great for public images, setting up a private image repository on the site involves some security key overhead that we don’t want to deal with. Instead, we’ll set up our own local image registry. We’ll then build, push, and run a sample Hello-Kenzan app from the local registry. (Later, we’ll use the registry to store the container images for our Kr8sswordz Puzzle app.</span></span></p>
<p><span><span>8. From the root directory of the cloned repository, set up the cluster registry by applying a .yaml manifest file.</span></span></p>
<pre>
<span><span>kubectl apply -f manifests/registry.yaml</span></span></pre>
<div>
<div>
<table>
<tbody>
<tr>
<td>
<p><span><span><img alt="9m-m-dyeYpMNvBD5Cxr3_GzLX-MrMKWZ9A9MGR-a" height="20" src="http://www.sickgaming.net/blog/wp-content/uploads/2018/10/set-up-a-ci-cd-pipeline-with-kubernetes-part-1-overview.png" width="20" /></span></span></p>
</td>
<td>
<p><span><span>Manifest .yaml files (also called </span><span>k8s files</span><span>) serve as a way of defining objects such as Pods or Deployments in Kubernetes. While previously we used the </span><span>run</span><span> command to launch a pod, here we are </span><span>applying</span><span> k8s files to deploy pods into Kubernetes.</span></span></p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p><span><span>9. Wait for the registry to finish deploying using the following command. Note that this may take several minutes. </span></span></p>
<pre>
<span><span>kubectl rollout status deployments/registry</span></span>
</pre>
<p><span><span>10. View the registry user interface in a web browser. Right now it’s empty, but you’re about to change that.</span></span></p>
<pre>
<span><span>minikube service registry-ui</span></span><span><span>​</span></span><span><span>​</span></span>
</pre>
<p><img alt="DUUet5TikWjRivAuP0aELBrwSx0QxKPBrOKfIzlB" height="283" src="https://lh4.googleusercontent.com/DUUet5TikWjRivAuP0aELBrwSx0QxKPBrOKfIzlBPBXvXeKZYfZEkwso1y27EbFcu4So4aYta7kB4Zwf3p5fgVlj3AaZKjhTactswluGmKD0PkjjwCqQQuLgzTTOYcG5RKWaAOiO" width="624" /></p>
<p><span><span>11. Let’s make a change to an HTML file in the cloned project. Open the </span><strong><span>/applications/hello-kenzan/index.html</span></strong><span> file in your favorite text editor, or run the command below to open it in the nano text editor. </span></span></p>
<pre>
<span>nano applications/hello-kenzan/index.html</span>
</pre>
<p><span><span>Change some text inside one of the </span><strong><span>&lt;p&gt;</span></strong><span> tags. For example, change “Hello from Kenzan!” to “Hello from Me!”. When you’re done, save the file. (In nano, press </span><span>Ctrl+X</span><span> to close the file, type </span><span>Y</span><span> to confirm the filename, and press </span><strong><span>Enter</span></strong><span> to write the changes to the file.) </span></span></p>
<p><span><span>12. Now let’s build an image, giving it a special name that points to our local cluster registry.</span></span></p>
<pre>
<span><span>docker build -t 127.0.0.1:30400/hello-kenzan:latest -f </span></span>
<span><span> applications/hello-kenzan/Dockerfile applications/hello-kenzan</span></span></pre>
<div>
<div>
<table>
<tbody>
<tr>
<td><span><img alt="9m-m-dyeYpMNvBD5Cxr3_GzLX-MrMKWZ9A9MGR-a" height="20" src="http://www.sickgaming.net/blog/wp-content/uploads/2018/10/set-up-a-ci-cd-pipeline-with-kubernetes-part-1-overview.png" width="20" /></span></td>
<td>
<p><span><span>When a docker image is tagged with a hostname prefix (as shown above), Docker will perform pull and push actions against a private registry located at the hostname as opposed to the default Docker Hub registry. </span></span></p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div><span><span>13. We’ve built the image, but before we can push it to the registry, we need to set up a temporary proxy. By default the Docker client can only push to HTTP (not HTTPS) via localhost. To work around this, we’ll set up a Docker container that listens on 127.0.0.1:30400 and forwards to our cluster.</span></p>
<p><span>First, build the image for our proxy container: </span></p>
<p></span></div>
<pre>
<span><span>docker build -t socat-registry -f applications/socat/Dockerfile applications/socat</span></span>
</pre>
<p><span><span>14. Now run the proxy container from the newly created image. (Note that you may see some errors; this is normal as the commands are first making sure there are no previous instances running.) </span></span></p>
<pre>
<span><span>docker stop socat-registry; docker rm socat-registry; </span></span> <span><span> docker run -d -e "REG_IP=`minikube ip`" -e "REG_PORT=30400" </span></span> <span><span> --name socat-registry -p 30400:5000 socat-registry</span></span></pre>
<div>
<div>
<table>
<tbody>
<tr>
<td><span><img alt="9m-m-dyeYpMNvBD5Cxr3_GzLX-MrMKWZ9A9MGR-a" height="20" src="http://www.sickgaming.net/blog/wp-content/uploads/2018/10/set-up-a-ci-cd-pipeline-with-kubernetes-part-1-overview.png" width="20" /></span></td>
<td>
<p><span><span>This step will fail if local port 30400 is currently in use by another process. You can check if there’s any process currently using this port by running the command</span><br class="kix-line-break" /><span>lsof -i :30400</span></span></p>
</td>
</tr>
</tbody>
</table>
</div>
<p><span><span>15. With our proxy container up and running, we can now push our hello-kenzan image to the local repository.</span></span></p>
<pre>
<span><span>docker push 127.0.0.1:30400/hello-kenzan:latest</span></span></pre>
<p><span><span>Refresh the browser window with the registry UI and you’ll see the image has appeared.</span></span></p>
<div><span><span><img alt="YSBsriST1ssQBC1z0Lewx67eZ8Lx4eeAkBNuW7gn" height="283" src="https://lh5.googleusercontent.com/YSBsriST1ssQBC1z0Lewx67eZ8Lx4eeAkBNuW7gn1ePXlJqnoEXYTPzVaiC-Ir3-x8CAFxH9SibqwWrmbBc4pe1Nray3hPqg-RAIKpglmuYpKrDi7oSugmbfwY-edoqKqF4SolgZ" width="624" /></span></span></div>
<div>
<p><span><span>16. </span></span><span>The proxy’s work is done for now, so you can go ahead and stop it.</span></p>
<pre>
<span>docker stop socat-registry</span></pre>
<p><span><span>17. With the image in our cluster registry, the last thing to do is apply the manifest to create and deploy the hello-kenzan pod based on the image.</span></span></p>
<pre>
<span><span>kubectl apply -f applications/hello-kenzan/k8s/deployment.yaml</span></span></pre>
<p><span><span>18. Launch a web browser and view the service.</span></span></p>
<pre>
<span><span>minikube service hello-kenzan</span></span></pre>
<p><span><span>Notice the change you made to the </span><strong><span>index.html</span></strong><span> file. That change was baked into the image when you built it and then was pushed to the registry. Pretty cool!</span></span></p>
<p><span><span><img alt="1Q5e2bfkbGFdwJWNa2LB16mkr1Y5dGx40Ep7DwEA" height="275" src="https://lh6.googleusercontent.com/1Q5e2bfkbGFdwJWNa2LB16mkr1Y5dGx40Ep7DwEARAbkmo0xnR6dO-MTmzus4KX8SfKVzVEq2bMJA8efZSxCwXKzoeSZojKVmspCG-EQdYcTUujZ3az6omYJSy3SADzwDbTggJR4" width="624" /></span></span></p>
<p><span><span>19. Delete the hello-kenzan deployment and service you created.</span></span></p>
<pre>
<span><span>kubectl delete service hello-kenzan</span>
<span>kubectl delete deployment hello-kenzan</span></span>
</pre>
<p><span><span>We are going to keep the registry deployment in our cluster as we will need it for the next few parts in our series. </span><span> </span></span></p>
<p><span><span>If you’re done working in Minikube for now, you can go ahead and stop the cluster by entering the following command:</span></span></p>
<pre>
<span><span>minikube stop</span></span>
</pre>
<div>
<table>
<tbody>
<tr>
<td>
<p><span><span>If you need to walk through the steps we did again (or do so quickly), we’ve provided npm scripts that will automate running the same commands in a terminal.  </span></span></p>
<p><span><span>1. To use the automated scripts, you’ll need to install NodeJS and npm. </span></span></p>
<p><span><span>On </span><strong><span>Linux</span></strong><span>, follow the </span><a href="https://nodejs.org/en/download/package-manager/"><span>NodeJS installation steps</span></a><span> for your distribution. To quickly install NodeJS and npm on Ubuntu 16.04 or higher, use the following terminal commands. </span></span></p>
<pre>
<span><span> a. curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -</span></span></pre>
<pre>
<span><span> b. sudo apt-get install -y nodejs</span></span></pre>
<p><span><span>On </span><strong><span>macOS</span></strong><span>, </span><a href="https://nodejs.org/en/"><span>download the NodeJS installer</span></a><span>, and then double-click the .pkg file to install NodeJS and npm.</span></span></p>
<p><span><span>2. C</span></span>hange directories to the cloned repository and install the interactive tutorial script:</p>
<pre> a. cd ~/kubernetes-ci-cd b. npm install</pre>
<p>3. <span><span>Start the script</span></span></p>
<pre>
<span> <span>npm run part1 (or part2, part3, part4 of the blog series)</span></span></pre>
<p>4. <span><span>Press<strong> </strong></span><strong><span>Enter</span></strong><span><strong> </strong>to proceed running each command. </span></span><span><span> </span></span></p>
</td>
</tr>
</tbody>
</table>
</div>
<h2>​Up Next</h2>
<p><span><span>In </span><span><strong>Part 2</strong> </span><span>of the series, we will continue to build out our infrastructure by adding in a CI/CD component: Jenkins running in its own pod. Using a Jenkins 2.0 Pipeline script, we will build, push, and deploy our Hello-Kenzan app, giving us the infrastructure for continuous deployment that will later be used with our Kr8sswordz Puzzle app.</span></span></p>
<p><em>This article was revised and updated by David Zuluaga, a front end developer at Kenzan. He was born and raised in Colombia, where he studied his BE in Systems Engineering. After moving to the United States, he studied received his master’s degree in computer science at Maharishi University of Management. David has been working at Kenzan for four years, dynamically moving throughout a wide range of areas of technology, from front-end and back-end development to platform and cloud computing. David’s also helped design and deliver training sessions on Microservices for multiple client teams.</em></p>
</div>
</div>
</div>
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum software by © MyBB Theme © iAndrew 2016