首页 > 解决方案 > Can I Assign Pod to a NIC?

问题描述

I have 1 master 1 node kubernetes cluster. On the node there are 2 network interface cards (in the same IP block and same sub-net but different IP).

Can i assign my pods to a special NIC ?

For example in docker we execute below command:

docker run -p 192.168.1.15:80:80 nginx

With above command nginx will run only on IP 192.168.1.15

So, can i achieve this on kubernetes?

标签: dockerkubernetes

解决方案


关于您的 docker 示例docker run -p 192.168.1.15:80:80 nginx

您可以使用没有选择器的服务

apiVersion: v1
kind: Service
metadata:
  name: nginx-svc
spec:
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80

由于该 Service 没有选择器,因此不会自动创建相应的 Endpoint 对象。您可以通过手动添加 Endpoint 对象,手动将服务映射到其运行的网络地址和端口:

apiVersion: v1
kind: Endpoints
metadata:
  name: nginx-svc
subsets:
  - addresses:
      - ip: 192.168.1.15
    ports:
      - port: 80

推荐阅读