Search code examples
kubernetesmanifest

Kubernetes manifest service for deployment


So final manifest will be next :

apiVersion: v1
kind: Service
metadata:
  name: apiserver-service
  labels:
    app: apiserver
spec:
  selector:
    app: apiserver
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8080
      nodePort: 30005
  type: NodePort

It will work for defining specific targetport


Solution

  • Service is an abstract way to expose your application running on a set of Pods. This one is a manifest for creating a service, here targetPort: 8080 is the pod port. In this manifest there are basically two parts, one is metadata which gives the service name and also give it a label. Then the spec part, which is short form of specification, it basically the specification of the service, here the selector is given, and also the ports are specified here, port represents the service port, targetPort represents the port on which the service will send requests. By nodePort the outside world (from outside the cluster) can communicate to the service, and finally type represents the type of the service. If the type = NodePort then it is basically means from outside the cluster the service will expose a port (nodePort).

    apiVersion: v1
    kind: Service
    metadata:
      name: apiserver-service
      labels:
        app: apiserver
    spec:
      selector:
        app: apiserver
      ports:
        - protocol: TCP
          port: 8080
          targetPort: 8080
          nodePort: 30005
      type: NodePort