<p>I need to setup some ROS nodes in a k8s environment and have been trying for the past few days to run a simple master + publisher + subscriber setup, without much luck. I started by following <a href="https://blog.zhaw.ch/icclab/challenges-with-running-ros-on-kubernetes/" rel="nofollow noreferrer">this guide</a>, but it uses pods to deploy the nodes, whereas I'm forced to use deployments. As soon as I change the .yaml files of the three components from a pod declaration to a deployment declaration, the publisher and the subscriber crash upon start since the can't connect to the ROS master anymore. There seems to be some problem connecting the pod generated by the deployment with its service, problem that is not present when I use a pod declaration: when I deploy the ROS master using pod declaration, the nodes can connect to it (but not to each other). Any idea on how to solve this?</p>
<p>Thank you!</p>
<p>Below you'll find the .yaml of the various components and services for completion:</p>
<p>Master (in pod version)</p>
<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: master
  labels:
    name: master
spec:
  containers:
   -  name: master
      image: ros:indigo
      ports:
        - containerPort: 11311
          name: master
      args:
          - roscore
</code></pre>
<p>Master service</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: master
spec:
  clusterIP: None
  ports:
    - port: 11311
      protocol: TCP
  selector:
    name: master
  type: ClusterIP
</code></pre>
<p>Publisher deployment:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: talker
  labels:
    app: talker
    name: talker
spec:
  replicas: 1
  selector:
    matchLabels:
      app: talker
  template:
    metadata:
      labels:
        app: talker
    spec:
      containers:
      - name: talker
        image: ros:indigo-ros-core
        env:
        - name: ROS_HOSTNAME
          value: talker
        - name: ROS_MASTER_URI
          value: http://master:11311
        args:
        - rostopic
        - pub
        - &quot;-r&quot;
        - &quot;1&quot;
        - my_topic
        - std_msgs/String
        - &quot;SPLab+ICClab&quot;
</code></pre>
<p>Publisher service:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: talker
spec:
  clusterIP: None
  ports:
    - port: 11311
      protocol: TCP
  selector:
    name: talker
  type: ClusterIP
</code></pre>
<p>Listener deployment:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: listener
  labels:
    app: listener
    name: listener
spec:
  replicas: 1
  selector:
    matchLabels:
      app: listener
  template:
    metadata:
      labels:
        app: listener
    spec:
      containers:
      - name: listener
        image: ros:indigo-ros-core
        env:
        - name: ROS_HOSTNAME
          value: listener
        - name: ROS_MASTER_URI
          value: http://master:11311
        args:
        - rostopic
        - echo
        - my_topic
</code></pre>
<p>Listener service:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: listener
spec:
  clusterIP: None
  ports:
    - port: 11311
      protocol: TCP
  selector:
    name: listener
  type: ClusterIP
</code></pre>

texdade
<p>Solved: the problem was that in the services I was using</p>
<pre><code>selector:
    name: listener
</code></pre>
<p>whereas in the deployments I was using</p>
<pre><code>selector:
    matchLabels:
      app: listener
  template:
    metadata:
      labels:
        app: listener
</code></pre>
<p>Changing <code>app: listener</code> to <code>name: listener</code> fixed the problem</p>
