简体   繁体   中英

Can a service be linked to pods with different images?

In Kubernetes , a Service is linked to a Deployment with the selector property of the Service and the label property of the Deployment.

Then, can a Service be linked to Deployments or pods with different images?

A Service can select all the pods whose labels are matched with service selector . It does not matter what images those pods have.

As far the k8s doc about service:

An abstract way to expose an application running on a set of Pods as a network service. With Kubernetes you don't need to modify your application to use an unfamiliar service discovery mechanism. Kubernetes gives Pods their own IP addresses and a single DNS name for a set of Pods, and can load-balance across them.

So as far your question, the answer is yes.

For example, let's say about this service yaml , for this service it will select all the pods that have app: MyApp label, it does not matter what are in those pods.

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

You can read more about Service then you will clear about it.

In kubernetes a service is not linked to Deployment. It is bound to all the pods using a 'selector'.

see below an example:

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

In this case, the below YAML creates a new Service object named "my-service", which targets TCP port 9376 on any Pod with the "app=my-app" label

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM