1.资源清单方式
将selector选择的标签改为指定pod的标签即可。
apiVersion: v1
kind: Service
metadata:
name: mysql-nodeport
namespace: testfenqu1
spec:
externalTrafficPolicy: Cluster
ports:
- nodePort: 31221
port: 3306
protocol: TCP
targetPort: 3306
selector:
app: testmysql001
operatorname: mysql-operator
sessionAffinity: None
type: NodePort
2.命令行方式
kubectl expose (-f FILENAME | TYPE NAME) [--port=port] [--protocol=TCP|UDP|SCTP] [--target-port=number-or-name]
[--name=name] [--external-ip=external-ip-of-service] [--type=type] [options]
例:为一个名为 tomcat的deploy资源创建nodeport服务
kubectl expose deploy tomcat --port=38080 --target-port=8080 --type=NodePort