Kwaker
Kwaker

Reputation: 45

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

Upvotes: 0

Views: 806

Answers (2)

Sahadat Hossain
Sahadat Hossain

Reputation: 4389

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

Upvotes: 2

Jonas
Jonas

Reputation: 129075

The first example in Kubernetes Service documentation Defining a Service contains what you ask, a Service where port: and targetPort: is different.

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: MyApp
  ports:
    - protocol: TCP
      port: 80
      targetPort: 9376

Upvotes: 1

Related Questions