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
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