Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • DevOps Lifecycle
  • DevOps Roadmap
  • Docker Tutorial
  • Kubernetes Tutorials
  • Amazon Web Services [AWS] Tutorial
  • AZURE Tutorials
  • GCP Tutorials
  • Docker Cheat sheet
  • Kubernetes cheat sheet
  • AWS interview questions
  • Docker Interview Questions
  • Ansible Interview Questions
  • Jenkins Interview Questions
Open In App
Next Article:
How to Deploy a Django Application in Kubernetes
Next article icon

How to Deploy Angular App in Kubernetes ?

Last Updated : 14 May, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In the modern world of web development, Angular has become one of the most popular frameworks for building dynamic and responsive web applications. As the demand for scalability and reliability increases, deploying these applications in a containerized environment using Kubernetes has become a common practice.

What is an Angular Application?

An Angular application is a client-side web application framework based on TypeScript, developed and maintained by Google. It's used for building dynamic, single-page web applications (SPAs) with a rich user interface. Angular provides a comprehensive set of tools and features for front-end development, including data binding, dependency injection, routing, forms handling, and more.

What is a Docker image?

A Docker image is a lightweight, standalone, and executable package that contains everything needed to run a piece of software within a Docker container. It serves as the basis for creating Docker containers.

What is Kubernetes?

Kubernetes is an open-source container orchestration platform developed by Google, now maintained by the Cloud Native Computing Foundation (CNCF). It automates the deployment, scaling, and management of containerized applications.

What is Kubernetes Pod?

In Kubernetes, a Pod is the smallest and simplest unit of deployment. It represents a single instance of a running process in the cluster.

To know more about Kubernetes pod - Read.

What is Kubernetes Service?

In Kubernetes, a Service is an abstraction that defines a logical set of Pods and a policy by which to access them. It provides a consistent way to access and expose applications running on a Kubernetes cluster, regardless of their individual Pod IP addresses or underlying infrastructure changes.

In this article we will learn how we can containerize angular application and deploy it using Kubernetes.

To know more about Kubernetes Service - Read.

Creating an Sample Angular Application

We can use an existing angular application or create a new one, the process to deploy them is the same.

We will start from scratch and create a new application, to create a new one we need to have angular cli globally installed. If you haven't, you can start by using the below command.

npm install -g @angular/cli

After that, we can use the following command,

ng new sample-app
cd sample-app

This will create a directory sample-app and change the current working directory to sample-app.

Creating a Dockerfile For Angular Application

By defining a Dockerfile, we will be able to create a docker image for our application.

Create a new file name Dockerfile in the root directory of our angular application.

# Dockerfile

# Stage 1: Build Angular application
FROM node AS builder
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
RUN npm run build

# Stage 2: Serve Angular application using nginx
FROM nginx:alpine
COPY --from=builder /app/dist/fresh-app/browser /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

This image will build our application and serve it using nginx reverse proxy listening at port 80. To create an image from this, we can use the docker cli command,

docker build .

Creating a Kubernetes Pod For Angular Application

We will use declarative approach to create our pod for this create a new file in the root directory of our angular application named pod.yaml,

# pod.yaml

apiVersion: v1
kind: Pod
metadata:
name: sample-angular-app
labels:
app: sample-angular-app
spec:
containers:
- name: sample-angular-app
image: dvalley56/sample-angular-app
resources:
limits:
memory: "128Mi"
cpu: "500m"
ports:
- containerPort: 80

Note: The value for the image needs to be a repository URL, simplest way is to make your own repo in docker hub.

To create a pod from this definition file, we can use the command,

kubectl apply -f pod.yaml

This will create a new Kubernetes pod.

To make sure pod is created without any error, we can use the below command and verify it.

kubectl get pods -o wide
Screenshot-2024-05-07-215732

Create a Service to Expose Angular Application to the Internet

Newly created pods are not accessible outside their own node, in order to access it from elsewhere we need to define a service that will forward our request to our pod.

Create a new file service.yaml,

# service.yaml

apiVersion: v1
kind: Service
metadata:
name: sample-angular-app-service
spec:
selector:
app: sample-angular-app
ports:
- port: 8080
targetPort: 80
type: LoadBalancer

Then to create a service from this definition we can use the command,

kubectl apply -f service.yaml

We can use the below command to verify if our service is running or not,

kubectl get services
Screenshot-2024-05-07-215836

Here, sample-angular-app-service is the service which we have created.Once our service is running we should be able to see our application at http://localhost:8080

Screenshot-2024-05-07-221021

Next Article
How to Deploy a Django Application in Kubernetes

D

dvalley56
Improve
Article Tags :
  • Kubernetes
  • DevOps
  • Kubernetes-Basics

Similar Reads

  • How to Deploy Angular App in S3?
    Nowadays, application deployment in web development is one of the crucial aspects to ensure the work is done efficiently and in a cost-saving way to be in line with the development cycle. Amazon S3 (Simple Storage Service), or Angular, is commonly referred to as a double-edged weapon for a data stor
    15 min read
  • How to Deploy Angular App in AWS
    Angular projects and applications are becoming more and more important as they are gaining popularity in the software industry, thus it becomes important to understand how we can deploy the angular apps that we create from the local system to the AWS cloud server, let us understand step by step how
    8 min read
  • How to Deploy a Django Application in Kubernetes
    In this article, we will study how we can deploy Django web applications to Kubernetes. We will also see how to dockerize and build an image of the Django application using Dockerfile. For this article, you should know about setting up a VM in Azure. We will see how to deploy applications on Linux S
    5 min read
  • How To Deploy Nginx In Kubernetes ?
    Kubernetes is an open-source container orchestration tool used to deploy, scale, and manage containerized applications. On the other hand, NGINX is a web service used for proxying and load balancing. Here in this article, I have first discussed what is Kubernetes and its features. Then I have discus
    8 min read
  • How to Deploy Java Application in Kubernetes?
    Kubernetes is a platform for automating deployment, scaling, and management of containerized applications. Pods are basic units that hold one or more containers. Deployments manage application deployment and updates. Services provide stable endpoints for accessing pods. Ingress manages external acce
    9 min read
  • How to Deploy Kubernetes on AWS?
    Kubernetes, the open-supply box orchestration platform, has emerged as the solution for dealing with containerized applications. When deploying Kubernetes in the cloud, Amazon Web Services (AWS) gives a robust and scalable environment. In this manual, we can walk you through the manner of deploying
    7 min read
  • How to Deploy Flask App on Kubernetes?
    A lightweight Python framework providing simplicity and flexibility in development, Flask can be utilized to create web applications. In contrast, Kubernetes is an effective framework for container orchestration that facilitates the deployment, scaling, and management of containerized applications.
    6 min read
  • How To Deploy Python Application In Kubernetes ?
    In today's IT world we are moving from the monolithic to microservice architecture to make our applications highly available and scalable to bring fault tolerance. In this transformation, containerization i.e., containerizing the application are a fundamental aspect of this micro services. In this a
    6 min read
  • How to Deploy Node.js Application in Kubernetes?
    Deploying the Node.js application on Kubernetes in a containerized manner makes it highly scalable,fault-tolerant, and allows for zero downtime. Kubernetes allows container orchestration that can be used in many ways during deployment. Load balancing is provided, which helps with automatic load tran
    4 min read
  • How to Deploy Spring Boot Application in Kubernetes ?
    The Spring Boot framework provides an assortment of pre-configured templates and tools to make the development of Java-based applications simpler. With little configuration, it enables developers to quickly design production-ready, stand-alone apps. Kubernetes, commonly referred to as K8s, is an ope
    7 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences