kubernetes nginx 部署 ERR_CONNECTION_REFUSED

kubernetes nginx deployment ERR_CONNECTION_REFUSED

我使用 minikube 来部署示例 nginx 镜像。
我想从本地主机 ex 访问 nginx:http://127.0.0.1:8080
我得到 ERR_CONNECTION_REFUSED

kubectl apply -f nginx.yml
部署。apps/nginx-deployment-name 已创建

kubectl apply -f nginx-service.yml
service/nginx-service-name 创建

部署yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment-name
  labels:
    name: nginx-deployment-name-label
spec:
  replicas: 3
  selector:
    matchLabels:
      name: nginx-template-name
  template:
    metadata:
      labels:
        name: nginx-template-name
    spec:
      containers:
      - name: nginx-container-name
        image: nginx
        ports:
        - containerPort: 8080

服务yml

apiVersion: v1
kind: Service
metadata:
  name: nginx-service-name
spec:
  selector:
    name: nginx-deployment-name-label
  type: NodePort
  ports:
  - name: http
    port: 8080
    targetPort: 8080
    nodePort: 30003
    protocol: TCP
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    name: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      name: nginx
  template:
    metadata:
      labels:
        name: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80

---
apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    name: nginx
spec:
  type: NodePort
  ports:
    - port: 80
      nodePort: 30080
      name: http
  selector:
    name: nginx

然后如果你在 minikube 上,例如:

➜  minikube ip
192.168.49.2

curl http://192.168.49.2:30080/