Answer is to use selector
apiVersion: v1
kind: Service
metadata:
name: mysql-service
labels:
app: mysql
spec:
selector:
app: mysql
ports:
- port: 3306
targetPort: 3306
nodePort: 30301
clusterIP: None
This specification will create a Service which targets TCP port 3306 on Pods with the app: mysql label, in other words, any pods with label app:mysql would be associated with this mysql-service automatically in Kubernetes
No comments:
Post a Comment