Home > Enterprise >  Scaling application with nodeport and without deployment with Pod
Scaling application with nodeport and without deployment with Pod

Time:07-31

I have an application with Pods that are not part of a deployments and I use services like nodePorts I access my application through ipv4:nodePorts/url-microservice when I want to scale my pods do I need to have a deployment with replicas? I tried using deployment with nodePorts but it doesn't work this way anymore: ipv4:nodePorts/url-microservice

I'll post my deployments and service for someone to see if I'm wrong somewhere

Deployments:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-gateway
  labels:
    app: my-gateway
spec:
  replicas: 1
  selector:
    matchLabels:
      run: my-gateway
  template:
    metadata:
      labels:
        run: my-gateway
    spec:
      containers:
      - name: my-gateway
        image: rafaelribeirosouza86/shopping:api-gateway
        imagePullPolicy: Always
        ports:
        - containerPort: 31534
          protocol: TCP
      imagePullSecrets:
        - name: regcred

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-adm-contact
  labels:
    app: my-adm-contact
spec:
  replicas: 1
  selector:
    matchLabels:
      run: my-adm-contact
  template:
    metadata:
      labels:
        run: my-adm-contact
    spec:
      containers:
      - name: my-adm-contact
        image: rafaelribeirosouza86/shopping:my-adm-contact
        imagePullPolicy: Always
        ports:
        - containerPort: 30001
          protocol: TCP
      imagePullSecrets:
        - name: regcred

Services:

apiVersion: v1
kind: Service
metadata:
  name: my-adm-contact-service
  namespace: default
spec:
#  clusterIP: 10.99.233.224
  ports:
  - port: 30001
    protocol: TCP
    targetPort: 30001
    nodePort: 30001
#  externalTrafficPolicy: Local
  selector:
    app: my-adm-contact
#  type: ClusterIP
#  type: LoadBalancer 
  type: NodePort

---

apiVersion: v1
kind: Service
metadata:
  name:  my-gateway-service
  namespace: default
spec:
#  clusterIP: 10.99.233.224
#   protocol:  ##The default is TCP
#   port: ##Exposes the service within the cluster. Also, other Pods use this to access the Service
#   targetPort: ##The service sends request while containers accept traffic on this port.
  ports:
  - port: 31534
    protocol: TCP
    targetPort: 31534
    nodePort: 31534
#  externalTrafficPolicy: Local
  selector:
    app: my-gateway
#  type: ClusterIP
#  type: LoadBalancer 
  type: NodePort

CodePudding user response:

Try:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-gateway
  ...
spec:
  ...
  template:
    metadata:
      labels:
        run: my-gateway  # <-- take note
  ...
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-adm-contact
  ...
spec:
  ...
  template:
    metadata:
      labels:
        run: my-adm-contact  # <-- take note
  ...
---
apiVersion: v1
kind: Service
metadata:
  name: my-adm-contact-service
  ...
  selector:
    run: my-adm-contact  # <-- wrong selector, changed from 'app' to 'run'
---
apiVersion: v1
kind: Service
metadata:
  name:  my-gateway-service
  ...
  selector:
    run: my-gateway  # <-- wrong selector, changed from 'app' to 'run'
  • Related