提问者:小点点

无法通过kubernetes中的服务访问应用程序[重复]


在kubernetes(我使用的是minikube)中,我使用kubectl application-f nginx部署部署了以下部署:

# nginx-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

我得到部署. apps/nginx-部署创建作为输出,当我运行kubectl获取部署时,我得到:

NAME               READY   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   3/3     3            3           22s

我还使用kubectl application-f nginx-service. yml命令部署了以下服务文件

apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  type: NodePort
  selector:
    app: nginx
  ports:
    - name: "http"
      port: 80
      targetPort: 80
      nodePort: 30080

输出是service/nginx-service创建kubectl get service的输出是:

NAME            TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
kubernetes      ClusterIP   10.96.0.1       <none>        443/TCP        127d
nginx-service   NodePort    10.99.253.196   <none>        80:30080/TCP   75s

但是,当我尝试通过在浏览器中输入10.99.253.196来访问应用程序时,它不会加载,当我尝试localhost:30080它显示无法连接。有人能帮助我理解为什么会发生这种情况/提供进一步的故障排除方向吗?


共1个答案

匿名用户

由于您使用的是minikube,因此您可能需要运行minikube服务nginx-service--url,这将创建一条通往集群的隧道并公开服务。