<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>The Ops Community ⚙️: lucasnscr</title>
    <description>The latest articles on The Ops Community ⚙️ by lucasnscr (@lucasnscr).</description>
    <link>https://community.ops.io/lucasnscr</link>
    <image>
      <url>https://community.ops.io/images/dWZKqAnqgmWYtI5KtrIi1aPhUbCZPhuyqxahc33wPbE/rs:fill:90:90/g:sm/mb:500000/ar:1/aHR0cHM6Ly9jb21t/dW5pdHkub3BzLmlv/L3JlbW90ZWltYWdl/cy91cGxvYWRzL3Vz/ZXIvcHJvZmlsZV9p/bWFnZS81Ni9mYjM1/ZmE2Ny0yZDdhLTRl/MGYtYWU5MS0xN2Rl/ZGVhODdiOTIuanBl/Zw</url>
      <title>The Ops Community ⚙️: lucasnscr</title>
      <link>https://community.ops.io/lucasnscr</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://community.ops.io/feed/lucasnscr"/>
    <language>en</language>
    <item>
      <title>Deployment spring application in Kubernetes with minikube</title>
      <dc:creator>lucasnscr</dc:creator>
      <pubDate>Wed, 25 May 2022 18:13:55 +0000</pubDate>
      <link>https://community.ops.io/lucasnscr/deployment-spring-application-in-kubernetes-with-minikube-25do</link>
      <guid>https://community.ops.io/lucasnscr/deployment-spring-application-in-kubernetes-with-minikube-25do</guid>
      <description>&lt;p&gt;&lt;a href="https://community.ops.io/images/kmhQsWyIuYQoHBSCq-T_4FPVW0uPOCMAX0wdRXn8nz0/w:880/mb:500000/ar:1/aHR0cHM6Ly9kZXYt/dG8tdXBsb2Fkcy5z/My5hbWF6b25hd3Mu/Y29tL3VwbG9hZHMv/YXJ0aWNsZXMvOXBp/aWhybmNuajR5cWVm/Y2gybnkuUE5H" class="article-body-image-wrapper"&gt;&lt;img src="https://community.ops.io/images/kmhQsWyIuYQoHBSCq-T_4FPVW0uPOCMAX0wdRXn8nz0/w:880/mb:500000/ar:1/aHR0cHM6Ly9kZXYt/dG8tdXBsb2Fkcy5z/My5hbWF6b25hd3Mu/Y29tL3VwbG9hZHMv/YXJ0aWNsZXMvOXBp/aWhybmNuajR5cWVm/Y2gybnkuUE5H" alt="Kubernetes, Spring and Docker" width="880" height="329"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Project description&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;🚀 This project aims to create an application with &lt;strong&gt;microservices architecture&lt;/strong&gt; using &lt;strong&gt;Spring&lt;/strong&gt; for all development. For &lt;strong&gt;virtualization&lt;/strong&gt;, &lt;strong&gt;Docker&lt;/strong&gt; is used to support our database allocation and create &lt;strong&gt;application container&lt;/strong&gt;s. To &lt;strong&gt;orchestrate our container&lt;/strong&gt;, &lt;strong&gt;Kubernetes&lt;/strong&gt; is used with &lt;strong&gt;Minikube&lt;/strong&gt; that provides us with all the context of a container cluster to receive our application and its surroundings.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/lucasnscr/Kubernetes-Spring"&gt;Here is the complete code of the project&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Installation and  Technologies&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The following technologies were used to carry out the project and it is necessary to install some items:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Docker&lt;/li&gt;
&lt;li&gt;Java 11&lt;/li&gt;
&lt;li&gt;Maven&lt;/li&gt;
&lt;li&gt;MiniKube&lt;/li&gt;
&lt;li&gt;Spring&lt;/li&gt;
&lt;li&gt;Postgres&lt;/li&gt;
&lt;li&gt;Docker&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Kubernetes&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Kubernetes is a &lt;strong&gt;portable&lt;/strong&gt;, &lt;strong&gt;extensible&lt;/strong&gt;, &lt;strong&gt;open-source&lt;/strong&gt; platform for managing containerized workloads and services, that facilitates both declarative configuration and automation. It has a large, rapidly growing ecosystem. Kubernetes services, support, and tools are widely available.&lt;/p&gt;

&lt;p&gt;Currently, k8s is &lt;strong&gt;one of the main DevOps tools&lt;/strong&gt;, as it is normally used in production environments and application approval. However, it is also possible to &lt;strong&gt;create a local cluster on a development machine&lt;/strong&gt;, which greatly &lt;strong&gt;facilitates the local testing of an application&lt;/strong&gt; and also increases the reliability of a new development, since the programming environment is much closer to the development environment. production.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;What are Pods?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Pods are the &lt;strong&gt;smallest deployable units of computing&lt;/strong&gt; that you can create and manage in Kubernetes.&lt;/p&gt;

&lt;p&gt;A Pod (as in a pod of whales or pea pod) is a group of one or more containers, with shared storage and network resources, and a specificationfor how to run the containers. A Pod's contents are always co-located and co-scheduled, and run in a shared context. A Pod models an application-specific "logical host": it contains one or more application containers which are relatively tightly coupled. &lt;strong&gt;In non-cloud contexts, applications executed on the same physical or virtual machine are analogous to cloud applications executed on the same logical host&lt;/strong&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;What are ConfigMaps ?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;ConfigMap is an API object used to store non-confidential data in key-value pairs&lt;/strong&gt;. Pods can consume ConfigMaps as environment variables, command-line arguments, or as configuration files in a volume. A ConfigMap allows you to decouple environment-specific configuration from your container images, so that your applications are easily portable.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;About Project&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The project has a Spotify plugin to automatically generate the docker image. Every project has its &lt;strong&gt;Dockerfile&lt;/strong&gt;. To generate the service image, you will need to run two commands.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mvn clean install
mvn dockerfile:build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After generating the artifacts you will need to &lt;strong&gt;install MiniKube&lt;/strong&gt; and &lt;strong&gt;kubectl&lt;/strong&gt;, assuming that these two items are already configured correctly, we select three commands, one to start the kubernetes cluster, enable the kubernetes dashboard that allows tracking the cluster with a visual interface and the other to stop it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;minikube start
minikube dashboard
minikube stop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For you to be** able to deploy your pods with local docker images**, you will need to run the command below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;eval $(minikube -p minikube docker-env)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command directs your minikube to use your local docker-env address in that terminal instance, so your pods will be uploaded using images that have already been built locally without necessarily being on DockerHub or some other image repository.&lt;/p&gt;

&lt;p&gt;With the cluster initialized, there are some commands that are important for us to &lt;strong&gt;see our pods, deployments, services and etc&lt;/strong&gt;. Below are two examples of commands to get what is operating in the cluster:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl get pods
kubectl get services
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Our application uses the Postgres database&lt;/strong&gt;, there is a directory within the project &lt;strong&gt;to make the database available on the cluster&lt;/strong&gt;, you need to run the commands below in sequence:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl create  -f  postgres.yaml
kubectl create  -f  postgres-service.yaml
kubectl port-forward svc/postgres 5000:5432
kubectl create -f config-map.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The respective commands create a deployment, a service, perform a database port forwarding inside k8s and create a configmap for the database.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Deploying the application on Kubernetes&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;After preparing our dependencies, we will &lt;strong&gt;deploy our three services that make up the application&lt;/strong&gt;. Each service will have a directory with the files related to the creation of config map, deployments and services. &lt;strong&gt;This is an important order to keep for the perfect execution of services on k8s&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl create -f configmap.yaml
kubectl create -f deployment.yaml
kubectl create -f service.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Running everything in this sequence will successfully run the services in Kubernetes. In case &lt;strong&gt;something fails&lt;/strong&gt; here follow some commands to kill the pod, the deployment and the service.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl delete deployment
kubectl delete service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, to follow the &lt;strong&gt;logs of your application&lt;/strong&gt;, you need to run the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl logs {pod name}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we finish a &lt;strong&gt;Project with three microservices and a database all running inside the Kubernetes cluste&lt;/strong&gt;r, where we can manage services and functionalities provided by the cluster.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>tutorials</category>
      <category>kubernetes</category>
    </item>
  </channel>
</rss>
