创建service
默认创建
kubectl expose deployment my-dep --port=8000 --target-port=80
apiVersion: v1
kind: Service
metadata:
labels:
app: my-dep
name: my-dep
spec:
selector:
app: my-dep
ports:
- port: 8000
protocol: TCP
targetPort: 80
ClusterIP方式(默认方式)
kubectl expose deployment my-dep --port=8000 --target-port=80 --type=ClusterIP
apiVersion: v1
kind: Service
metadata:
labels:
app: my-dep
name: my-dep
spec:
ports:
- port: 8000
protocol: TCP
targetPort: 80
selector:
app: my-dep
type: ClusterIP
NodePort方式
kubectl expose deployment my-dep --port=8000 --target-port=80 --type=NodePort
apiVersion: v1
kind: Service
metadata:
labels:
app: my-dep
name: my-dep
spec:
ports:
- port: 8000
protocol: TCP
targetPort: 80
selector:
app: my-dep
type: NodePort
查看service
kubectl get service
kubectl get svc
#查看所有
kubectl get svc -A
访问service
#宿主机、pod ip访问
kubectl get service
curl 10.110.134.55:8000
#pod内域名访问
curl my-dep.default.svc:8000
#浏览器访问,NodePort方式
106.12.145.172:32237
删除service
kubectl delete svc my-dep