k8s service指定暴露ip端口号
vi deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: web6
namespace: default
spec:
replicas: 3
selector:
matchLabels:
app: web6
template:
metadata:
labels:
app: web6
spec:
containers:
- name: nginx
image: nginx:1.16
# 存活检查
livenessProbe:
httpGet:
path: /index.html
port: 80
initialDelaySeconds: 5
periodSeconds: 10
# 就绪检查
readinessProbe:
httpGet:
path: /index.html
port: 80
initialDelaySeconds: 6
periodSeconds: 10
---
apiVersion: v1
kind: Service
metadata:
name: web6
namespace: default
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
nodePort: 30901
selector:
app: web6
type: NodePort
可以通过nodePort属性来固定暴露IP端口号。(端口号范围只能是 30000-32767 )
nodePort: 30901
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/d1ef4bab340ea20fa8ea6587faa750a9.png)
kubectl apply -f deploy.yaml
访问(ip:30901)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/5dae4bc962cfbccbfa6da0a7f87cdec2.png)