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 this guide, 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?
Thank you!
Below you'll find the .yaml of the various components and services for completion:
Master (in pod version)
apiVersion: v1
kind: Pod
metadata:
name: master
labels:
name: master
spec:
containers:
- name: master
image: ros:indigo
ports:
- containerPort: 11311
name: master
args:
- roscore
Master service
apiVersion: v1
kind: Service
metadata:
name: master
spec:
clusterIP: None
ports:
- port: 11311
protocol: TCP
selector:
name: master
type: ClusterIP
Publisher deployment:
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
- "-r"
- "1"
- my_topic
- std_msgs/String
- "SPLab+ICClab"
Publisher service:
apiVersion: v1
kind: Service
metadata:
name: talker
spec:
clusterIP: None
ports:
- port: 11311
protocol: TCP
selector:
name: talker
type: ClusterIP
Listener deployment:
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
Listener service:
apiVersion: v1
kind: Service
metadata:
name: listener
spec:
clusterIP: None
ports:
- port: 11311
protocol: TCP
selector:
name: listener
type: ClusterIP
Solved: the problem was that in the services I was using
selector:
name: listener
whereas in the deployments I was using
selector:
matchLabels:
app: listener
template:
metadata:
labels:
app: listener
Changing app: listener
to name: listener
fixed the problem