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

在这里插入图片描述

 kubectl apply -f deploy.yaml

访问(ip:30901)

在这里插入图片描述

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐