首页 > 解决方案 > 我在使用 minikube 的 kubernetes 中遇到了这个错误

问题描述

我尝试使用 kubernetes 部署 nginx 服务器。我能够创建部署并创建服务。但是当我给出 curl 命令时,我面临一个错误。我无法在浏览器中卷曲和打开 nginx 网页。以下是我使用的命令和我得到的错误。

kubectl get pods

NAME                                READY   STATUS              RESTARTS   AGE
curl                                1/1     Running             8          15d
curl-deployment-646445496f-59fs9    1/1     Running             7          15d
hello-5d448ffc76-cwzcl              1/1     Running             13         23d
hello-node-7567d9fdc9-ffdkx         1/1     Running             8          20d
my-nginx-5b6fb7fb46-bdzdq           0/1     ContainerCreating   0          15d
mytestwebapp                        1/1     Running             10         21d
nginx-6799fc88d8-w76cb              1/1     Running             5          13d
nginx-deployment-66b6c48dd5-9mkh8   1/1     Running             12         23d
nginx-test-795d659f45-d9shx         1/1     Running             4          13d
rss-site-7b6794856f-9586w           2/2     Running             40         15d
rss-site-7b6794856f-z59vn           2/2     Running             78         21d
jit@jit-Vostro-15-3568:~$ kubectl logs webserver
Error from server (NotFound): pods "webserver" not found


jit@jit-Vostro-15-3568:~$ kubectl get svc


NAME         TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                        AGE
hello-node   LoadBalancer   10.104.134.171   <pending>     8080:31733/TCP                 13d
kubernetes   ClusterIP      10.96.0.1        <none>        443/TCP                        23d
my-nginx     NodePort       10.103.114.92    <none>        8080:32563/TCP,443:32397/TCP   15d
nginx        NodePort       10.110.113.60    <none>        80:30985/TCP                   13d
nginx-test   NodePort       10.109.16.192    <none>        8080:31913/TCP                 13d


jit@jit-Vostro-15-3568:~$ curl kube-worker-1:30985


curl: (6) Could not resolve host: kube-worker-1

标签: kubernetes

解决方案


如您所见,您已调用 pod nginx,这表明您nginx已经在集群的 pod 中部署了服务器。你没有调用 podwebserver这就是你得到的原因

Error from server (NotFound): pods "webserver" not found  error.

还要访问 nginx 服务,尝试通过 curl 传递它ip:port

$ curl 10.110.113.60:30985

如果您将 Web 浏览器指向http://IP_OF_NODE:ASSIGNED_PORT(其中 IP_OF_NODE 是您的一个节点的 IP 地址,ASSIGNED_PORT 是在创建服务命令期间分配的端口),您应该会看到 NGINX 欢迎页面!

看一下:nginx-app-kubernetes


推荐阅读