<?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>DEV Community: Saiprasad Tirumala</title>
    <description>The latest articles on DEV Community by Saiprasad Tirumala (@saiprasad2595).</description>
    <link>https://dev.to/saiprasad2595</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F795639%2Ff7ac120d-3944-4da6-ade6-ea35791f6987.jpeg</url>
      <title>DEV Community: Saiprasad Tirumala</title>
      <link>https://dev.to/saiprasad2595</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/saiprasad2595"/>
    <language>en</language>
    <item>
      <title>Deploy Angular application on Kubernetes</title>
      <dc:creator>Saiprasad Tirumala</dc:creator>
      <pubDate>Wed, 26 Jan 2022 17:46:01 +0000</pubDate>
      <link>https://dev.to/saiprasad2595/deploy-angular-application-on-kubernetes-3n2f</link>
      <guid>https://dev.to/saiprasad2595/deploy-angular-application-on-kubernetes-3n2f</guid>
      <description>&lt;p&gt;&lt;strong&gt;Prerequisites:&lt;/strong&gt;&lt;br&gt;
Nodejs Installed.&lt;br&gt;
Docker Installed.&lt;br&gt;
Kubernetes Installed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Create an angular application&lt;/strong&gt;&lt;br&gt;
Install angular CLI using below command &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

npm install -g @angular/cli


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Below command helps you to create an Angular application.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

ng new hello-world


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Alternatively you can clone from my repository &lt;a href="https://github.com/saiprasad2595/angular-kubernetes" rel="noopener noreferrer"&gt;link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now go inside the hello-world directory and run the local server using below command.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

ng serve


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;By default application runs on port number 4200.You can test in your browser using this &lt;a href="http://localhost:4200" rel="noopener noreferrer"&gt;link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Build the application in production environment&lt;/strong&gt;&lt;br&gt;
Run the below command which creates the dist folder in your root directory.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

ng build --prod


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1481tpat6x3kmp2ez7xc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1481tpat6x3kmp2ez7xc.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Create a DockerFile&lt;/strong&gt;&lt;br&gt;
We need to copy the files from dist folder to nginx path.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

FROM nginx:alpine
COPY ./dist/hello-world ./usr/share/nginx/html


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Build the DockerFile&lt;/strong&gt;&lt;br&gt;
Navigate to the directory where you created the Dockerfile and  enter the below command.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

docker build -t angular/hello-world:v1 .


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4maz5n5hdmrgl628t578.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4maz5n5hdmrgl628t578.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Once the build process is completed, You can check the docker images with below command.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

docker ps -a


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step 5: Create a kubernetes Deployment Pod&lt;/strong&gt; &lt;br&gt;
You can get deployment file from my github repository &lt;a href="https://github.com/saiprasad2595/angular-kubernetes/blob/master/deployment.yaml" rel="noopener noreferrer"&gt;link&lt;/a&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

kubectl apply -f deployment.yaml


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg5cvx60riyhtdcyyq29z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg5cvx60riyhtdcyyq29z.png" alt="deployment.yaml"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Explanation for above YAML in short:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sample template for Deployment file can be found in official &lt;a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/" rel="noopener noreferrer"&gt;site&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;apiVersion defines the version of kubernetes.&lt;/li&gt;
&lt;li&gt;kind indicates the type if it is a Deployment, Service, Job etc.&lt;/li&gt;
&lt;li&gt;metadata is the deployment name.&lt;/li&gt;
&lt;li&gt;Under spec.template.spec.containers, we need to mention the name of the docker image.
In this example, we haven't pushed Docker image to its registry. So we need to mention imagePullPolicy: Never. If it is not mentioned, kubernetes tries to pull the image from the docker registry. &lt;/li&gt;
&lt;li&gt;containerPort tells in which port our deployment needs to run.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 6: Create a Service&lt;/strong&gt;&lt;br&gt;
You can get service file from my github repository &lt;a href="https://github.com/saiprasad2595/angular-kubernetes/blob/master/service.yaml" rel="noopener noreferrer"&gt;link&lt;/a&gt;&lt;br&gt;
Enter the below command to create a service pod.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

kubectl apply -f service.yaml


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3etb7mb47tp454t6ypgl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3etb7mb47tp454t6ypgl.png" alt="service.yaml"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Service pod helps in connecting to the application based on the  deployment name mentioned under spec.selector.app&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Verify the deployments&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

kubectl get all


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk88jby5485wrpfqpeclw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk88jby5485wrpfqpeclw.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 7: Final Step - Port Forwarding&lt;/strong&gt;&lt;br&gt;
This helps in forwarding our requests to our application&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

kubectl port-forward &amp;lt;service-name&amp;gt; &amp;lt;expose port no&amp;gt;:&amp;lt;service port num&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhaiezs5stgiexolv0hzi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhaiezs5stgiexolv0hzi.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Now go to your browser and check by hitting (&lt;a href="http://localhost:80" rel="noopener noreferrer"&gt;http://localhost:80&lt;/a&gt;). You should able to access your web application.  &lt;/p&gt;

</description>
      <category>angular</category>
      <category>kubernetes</category>
      <category>docker</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
