NS + Pod Limitation
To create a namespace for your application and specify resource limits for the container, you can modify your Kubernetes configuration files as follows:
- Define the namespace.
- Update your Deployment to use the new namespace.
- Add resource limits to the container specification.
Here's the updated configuration:
Namespace Definition
apiVersion: v1
kind: Namespace
metadata:
name: hdfc-upi-namespace
Deployment with Resource Limits
apiVersion: apps/v1
kind: Deployment
metadata:
name: hdfc-upi-deployment
namespace: hdfc-upi-namespace
spec:
replicas: 1
selector:
matchLabels:
app: hdfc-upi
template:
metadata:
labels:
app: hdfc-upi
spec:
containers:
- name: hdfc-upi
image: ahmadmcsam/hdfc-upi:0.0.0.8
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8001
resources:
limits:
memory: "500Mi"
cpu: "0.5"
requests:
memory: "500Mi"
cpu: "0.5"
imagePullSecrets:
- name: dockerhubcred
NodePort Service
apiVersion: v1
kind: Service
metadata:
name: hdfc-upi-svc-nodeport
namespace: hdfc-upi-namespace
spec:
selector:
app: hdfc-upi
ports:
- protocol: TCP
port: 8001
targetPort: 8001
nodePort: 30002
type: NodePort
ClusterIP Service
apiVersion: v1
kind: Service
metadata:
name: hdfc-upi-svc-clusterip
namespace: hdfc-upi-namespace
spec:
selector:
app: hdfc-upi
ports:
- protocol: TCP
port: 8001
targetPort: 8001
type: ClusterIP
Full Configuration
Combining all parts, the complete configuration file will look like this:
apiVersion: v1
kind: Namespace
metadata:
name: hdfc-upi-namespace
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: hdfc-upi-deployment
namespace: hdfc-upi-namespace
spec:
replicas: 1
selector:
matchLabels:
app: hdfc-upi
template:
metadata:
labels:
app: hdfc-upi
spec:
containers:
- name: hdfc-upi
image: ahmadmcsam/hdfc-upi:0.0.0.8
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8001
resources:
limits:
memory: "500Mi"
cpu: "0.5"
requests:
memory: "500Mi"
cpu: "0.5"
imagePullSecrets:
- name: dockerhubcred
---
apiVersion: v1
kind: Service
metadata:
name: hdfc-upi-svc-nodeport
namespace: hdfc-upi-namespace
spec:
selector:
app: hdfc-upi
ports:
- protocol: TCP
port: 8001
targetPort: 8001
nodePort: 30002
type: NodePort
---
apiVersion: v1
kind: Service
metadata:
name: hdfc-upi-svc-clusterip
namespace: hdfc-upi-namespace
spec:
selector:
app: hdfc-upi
ports:
- protocol: TCP
port: 8001
targetPort: 8001
type: ClusterIP
This configuration will create a namespace hdfc-upi-namespace
, deploy the hdfc-upi
application within that namespace with specified resource limits, and define both NodePort
and ClusterIP
services within the same namespace.