How to Deploy Angular App in Kubernetes ?
Last Updated :
14 May, 2024
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

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

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
Similar Reads
Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co
11 min read
Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance
10 min read
Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact
12 min read
Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and
9 min read
3-Phase Inverter An inverter is a fundamental electrical device designed primarily for the conversion of direct current into alternating current . This versatile device , also known as a variable frequency drive , plays a vital role in a wide range of applications , including variable frequency drives and high power
13 min read
Polymorphism in Java Polymorphism in Java is one of the core concepts in object-oriented programming (OOP) that allows objects to behave differently based on their specific class type. The word polymorphism means having many forms, and it comes from the Greek words poly (many) and morph (forms), this means one entity ca
7 min read
What is Vacuum Circuit Breaker? A vacuum circuit breaker is a type of breaker that utilizes a vacuum as the medium to extinguish electrical arcs. Within this circuit breaker, there is a vacuum interrupter that houses the stationary and mobile contacts in a permanently sealed enclosure. When the contacts are separated in a high vac
13 min read
CTE in SQL In SQL, a Common Table Expression (CTE) is an essential tool for simplifying complex queries and making them more readable. By defining temporary result sets that can be referenced multiple times, a CTE in SQL allows developers to break down complicated logic into manageable parts. CTEs help with hi
6 min read
Spring Boot Interview Questions and Answers Spring Boot is a Java-based framework used to develop stand-alone, production-ready applications with minimal configuration. Introduced by Pivotal in 2014, it simplifies the development of Spring applications by offering embedded servers, auto-configuration, and fast startup. Many top companies, inc
15+ min read
Python Variables In Python, variables are used to store data that can be referenced and manipulated during program execution. A variable is essentially a name that is assigned to a value. Unlike many other programming languages, Python variables do not require explicit declaration of type. The type of the variable i
6 min read