I have created a deployment with 2 replica sets. But the Service exposes the 8080 and the management endpoint using NodePort. How should I set up the pods deployment if Prometheus deployment should get 2 targets instead of one (the k8s service port mapping)
I have a deployment.yaml creating 2 replicas:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: rps-app # Deployment manages the pods with these labels
name: rps-app-deployment
spec:
replicas: 2
selector:
matchLabels: # This replicaSet manages the pods with these labels
app: rps-app
minReadySeconds: 10
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
type: RollingUpdate
template:
metadata:
labels:
app: rps-app
name: rps-app-deployment
spec:
hostname: rps-app
restartPolicy: Always
containers:
- image: edekargaurav88/rps2:1.4
name: rps-app
imagePullPolicy: Always
resources:
limits:
cpu: "1"
memory: 512M
requests:
cpu: "0.5"
memory: 256M
ports:
- containerPort: 8080
#hostPort: 8080
name: http
- containerPort: 8091
#hostPort: 8091
name: metrics
env:
- name: POSTGRES_USER
value: postgres
- name: POSTGRES_PASSWORD
value: postgres
- name: POSTGRES_URL
value: jdbc:postgresql://192.168.10.220:5432/postgres
- name: SPRING_PROFILES_ACTIVE
value: prod,liquibase
livenessProbe:
httpGet:
path: /actuator/health
port: 8091
scheme: HTTP
initialDelaySeconds: 60
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 6
readinessProbe:
httpGet:
path: /actuator/health
port: 8091
scheme: HTTP
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 5
My Service yaml:
apiVersion: v1
kind: Service
metadata:
name: rps-app
spec:
allocateLoadBalancerNodePorts: true # default
selector:
app: rps-app
type: NodePort
ports:
- protocol: TCP
port: 8080
targetPort: 8080
name: app
- protocol: TCP
port: 8091
targetPort: 8091
name: health