Can I Assign Pod to a NIC?

7/30/2019

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?

-- akuscu
docker
kubernetes

2 Answers

7/31/2019

With regards to your docker example docker run -p 192.168.1.15:80:80 nginx

you can use service without selectors

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

Because this Service has no selector, the corresponding Endpoint object is not created automatically. You can manually map the Service to the network address and port where it’s running, by adding an Endpoint object manually:

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

7/30/2019

From my quick research K8S does not seem to support this. You can assign a Service to an IP address and port but pods are meant to be disposable and non-critical. Networking routing is handled by the Ingress Controller. If a pod is associated with a specific IP then the pod is no longer a commodity concept but rather a known quantity.

My assumption is that you want to be able to access the pod directly, if that is the case try the port forwarding mechanic that leverages the aforementioned Ingress Controller.

-- David J Eddy
Source: StackOverflow