Curl请求到minikube超时,不理解为什么。

huangapple go评论94阅读模式
英文:

Curl requests to minikube time out, dont understand why

问题

我正在阅读《Cloud Native Patterns》第5章(Cornelia Davis,Manning Press,(c)2019)的内容。我尝试通过curl命令访问minikube服务,但始终超时。

我在运行Windows 10 Home计算机上进行操作。它装有Docker(带有虚拟机箱),Minikube,kubectl,MySql 8和OpenJdk 1.8。我正在使用由GIT提供的Bash终端(MINGW64)。

按照说明,我使用作者提供的应用程序(connection,post,connection+post)并使用Maven编译了它们。然后,我将它们上传到了我的Docker Hub帐户,以便Docker可以使用它们。然后,我通过kubectl启动了mysql-svc,就像教程告诉我的那样。

在启动mysql后,我使用minikube service mysql-svc --format ... 命令获取IP:Port,并将其安装到每个connection服务和post服务的YAML文件中。我启动了这两个服务,它们瞬间就开始运行了。

这是我的集群状态:

$ kubectl get all
NAME                              READY   STATUS             RESTARTS   AGE
pod/connections-56bcf7896-h4tz7   0/1     CrashLoopBackOff   8          26m
pod/mysql-7dbfd4dbc4-2jsjt        1/1     Running            0          24h
pod/posts-5d7f46b546-crfmj        1/1     Running            1          102s

NAME                      TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
service/connections-svc   NodePort    10.104.27.91    <none>        80:31286/TCP     26m
service/kubernetes        ClusterIP   10.96.0.1       <none>        443/TCP          2d12h
service/mysql-svc         NodePort    10.107.19.70    <none>        3306:31067/TCP   24h
service/posts-svc         NodePort    10.97.232.158   <none>        80:31651/TCP     103s

NAME                          READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/connections   0/1     1            0           26m
deployment.apps/mysql         1/1     1            1           24h
deployment.apps/posts         1/1     1            1           103s

NAME                                    DESIRED   CURRENT   READY   AGE
replicaset.apps/connections-56bcf7896   1         1         0       26m
replicaset.apps/mysql-7dbfd4dbc4        1         1         1       24h
replicaset.apps/posts-5d7f46b546        1         1         1       103s

好的,posts服务正在运行。因此,请尝试请求一些内容:

$ curl $(minikube service --url posts-svc)/posts
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:02 --:--:--     0
curl: (7) Failed to connect to 192.168.99.101 port 31651: Connection refused

我不知道为什么连接被拒绝,有人能解释一下吗?或者至少提供一种方法来解释为什么连接被拒绝,尽管我已经确保了IP:Port是正确的。

可能相关的问题是服务一直崩溃。甚至不到四分钟,posts-svc就已经多次崩溃:

$ kubectl get all
NAME                              READY   STATUS             RESTARTS   AGE
pod/connections-56bcf7896-h4tz7   0/1     CrashLoopBackOff   9          28m
pod/mysql-7dbfd4dbc4-2jsjt        1/1     Running            0          24h
pod/posts-5d7f46b546-crfmj        0/1     CrashLoopBackOff   3          3m53s
[SNIP]

如何获得更稳定的表现?

谢谢,

Jerome。

2020年8月11日更新:

在查看日志后,我更改了以下内容:

  • minikube启动文件mysql-deployment.yaml现在明确使用密码,例如

    containers:
    - name: mysql
      image: mysql:5.7.22
      env:
        - name: MYSQL_ROOT_PASSWORD
          value: "the_actual_password";
    
  • 我在application.properties文件中添加了一个方言。现在,示例的h2测试文件不喜欢那个方言,因此我重新编译时跳过了测试。稍后我可以为测试添加一个h2方言。

      spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL57Dialect
    

现在我只是得到根用户无法登录的消息:

    java.sql.SQLException: Access denied for user 'root'@'172.17.0.1' (using password: YES)

从mysql CLI中,我可以作为root登录并访问此代码使用的'cookbook'数据库。我检查了root拥有所有授权等。它只是不起作用。

还有更多线索吗?

Jerome。

2020年8月12日更新:

我现在有了良好的结果。以下是我投诉和现在之间的不同之处。

教程让我通过Docker下载MySQL版本。然而,我的计算机上也有一个PC版本的MySQL。我认为Docker / Minikube服务器会以某种方式使用下载的MySQL来连接我的桌面MySQL。因此,我修改了下载命令以及用于启动mysql-svc的Minikube启动.yaml文件,以复制使用MySQL的版本号,密码以及可能的其他方面。结果是程序和mysql彼此不喜欢,所以服务不断重启。

正确的方法

英文:

I'm working thru Chapter 5 of Cloud Native Patterns (Cornelia Davis, Manning Press, (c) 2019). I'm trying to access a minikube service thru a curl command, but consistently time out.

I'm running on a Windows 10 Home computer. It has Docker (with virtual box), Minikube, kubectl, MySql 8, and OpenJdk 1.8. I'm using the Bash terminal (MINGW64) provided by GIT.

Per instructions, I'm using the author's provided apps (connection, post, connection+post) and compiled them with Maven. I then uploaded them to my Docker Hub account, so that Docker can use them. Then I started mysql-svc thru kubectl, just as the tutorial tells me to.

After starting mysql, I used a minikube service mysql-svc --format ... command to get the IP:Port and installed it into the YAML file for each of the connection service and post service. I started the two services, and they -- momentarily -- were up and running.

Here is my cluster status:

$ kubectl get all
NAME                              READY   STATUS             RESTARTS   AGE
pod/connections-56bcf7896-h4tz7   0/1     CrashLoopBackOff   8          26m
pod/mysql-7dbfd4dbc4-2jsjt        1/1     Running            0          24h
pod/posts-5d7f46b546-crfmj        1/1     Running            1          102s

NAME                      TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
service/connections-svc   NodePort    10.104.27.91    &lt;none&gt;        80:31286/TCP     26m
service/kubernetes        ClusterIP   10.96.0.1       &lt;none&gt;        443/TCP          2d12h
service/mysql-svc         NodePort    10.107.19.70    &lt;none&gt;        3306:31067/TCP   24h
service/posts-svc         NodePort    10.97.232.158   &lt;none&gt;        80:31651/TCP     103s

NAME                          READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/connections   0/1     1            0           26m
deployment.apps/mysql         1/1     1            1           24h
deployment.apps/posts         1/1     1            1           103s

NAME                                    DESIRED   CURRENT   READY   AGE
replicaset.apps/connections-56bcf7896   1         1         0       26m
replicaset.apps/mysql-7dbfd4dbc4        1         1         1       24h
replicaset.apps/posts-5d7f46b546        1         1         1       103s

OK, the posts service is up. So ask it for something:

$ curl $(minikube service --url posts-svc)/posts
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:02 --:--:--     0
curl: (7) Failed to connect to 192.168.99.101 port 31651: Connection refused

I don't know why it is refusing, and can someone explain? Or at least provide an approach for why connections are refused, even though I've got the IP:Port correct.

A perhaps related problem is that the services keep crashing. Not even four minutes later and the posts-svc has crashed multiple times:

$ kubectl get all
NAME                              READY   STATUS             RESTARTS   AGE
pod/connections-56bcf7896-h4tz7   0/1     CrashLoopBackOff   9          28m
pod/mysql-7dbfd4dbc4-2jsjt        1/1     Running            0          24h
pod/posts-5d7f46b546-crfmj        0/1     CrashLoopBackOff   3          3m53s
[SNIP]

How might I get more stability here?

Thanks,

Jerome.

UPDATE 8/11/2020:

After looking through logs I changed these things:

  • The minikube startup file mysql-deployment.yaml now explicitly uses the password, such as

    containers:
    - name: mysql
      image: mysql:5.7.22
      env:
        - name: MYSQL_ROOT_PASSWORD
          value: &quot;the_actual_password&quot;
    
  • I added a dialect to the application.properties file. Now the example's h2 test files don't like that dialect, so I recompiled skipping the tests. I can add an h2 dialect to the tests later on.

      spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL57Dialect
    

Now all I get is that the root user can't login:

    java.sql.SQLException: Access denied for user &#39;root&#39;@&#39;172.17.0.1&#39; (using password: YES)

From the mysql CLI, I can login as root and access the 'cookbook' database that this code uses. I checked that root has all grants, etc. It just doesn't work.

Any more clues?

Jerome.

UPDATE ON 8/12/2020:

I have good results now. Here is what is different between my complaint and now.

The tutorial had me download a MySQL version thru Docker. However, I also have a PC version of MySQL on my computer. I thought that the Docker / Minikube servers would somehow use the downloaded MySQL to connect to my desktop MySQL. So I modified the download command, and the .yaml file used to do the Minikube startup of mysql-svc, to duplicate the version #, password, and possibly other aspects of using MySQL. The net effect is that the program and mysql don't like each other, so the services keep restarting.

The correct way to approach Minikube is that all of the needed software is downloaded into the container, and it doesn't touch what is already there. I read that but didn't obviously understand it. Now I have burned fingers, and see that the container has all the programs I need.

So I restored all configuration to what the GIT repository started with, and I replaced the mysql I originally installed (version 8.+, to match my desktop) with the one the tutorial asked for (5.7.22).

After recompiling, and then pushing the changes to my Docker Hub account, everything works just as the tutorial promised. Note that this book has a number of typos in commands, notably missing the clause '--url' in "minikube service..." commands on p.121. Be wary.

My earlier accounting said that I created my files "per instructions", but I was blind to the changes that I actually made.

Jerome.

Sorry, Yet Another UPDATE on 08/13/2020:

I said I eventually used the .yaml configuration files exactly as provided. I actually made two changes.

  1. The files had apiVersion: apps/v1beta . This must become apps/v1 or
    other things don't work.

  2. The files sought their Docker Hub images as cdavisafc/*, such as cdavisafc/cloudnative-statelessness-posts. Because I put the images into my own Docker Hub account, my images are named logicaltiger/cloudnative-statelessness-posts, etc.

The tutorial says good things, but you'll learn plenty about docker and minikube just thru getting the provided code to actually deploy OK.

Jerome.

答案1

得分: 1

当启动minikube时,请尝试调整RAM和内存(--cpus 4 --memory 8192),前提是您的计算机具备这些资源可用。

似乎minikube没有足够的资源来正确执行其任务。

当可用资源不足时,Minikube在启动时可能会很脆弱,如果资源不足,您可能需要多次停止/启动,直到它正确启动。

英文:

When starting minikube, try adjusting RAM and memory (--cpus 4 --memory 8192, given your computer have those resources available).
It seems like minikube is not having enough resources to perform it's own tasks correctly.

Minikube is fragile when it comes to lack of available resources and if resources are low, you might need to stop/start multiple times until it boots up correctly.

答案2

得分: 0

您可能还希望运行一些诊断以获取有关为什么您的Pod崩溃的更多信息。

kubectl describe pod connections-56bcf7896-h4tz7
kubectl describe pod posts-5d7f46b546-crfmj
kubectl describe deployment connections
kubectl describe deployment posts
kubectl logs connections-56bcf7896-h4tz7
kubectl logs posts-5d7f46b546-crfmj

您应该从这些命令中获得一些关于为什么您的Pod失败的指示。

英文:

You might also want to run some diagnostics to get more information as to why your pods are crashing.

kubectl describe pod connections-56bcf7896-h4tz7
kubectl describe pod posts-5d7f46b546-crfmj
kubectl describe deployment connections
kubectl describe deployment posts
kubectl logs connections-56bcf7896-h4tz7
kubectl logs posts-5d7f46b546-crfmj

You should get some indication from those commands as to why your pods are failing.

huangapple
  • 本文由 发表于 2020年8月7日 10:47:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/63294459.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定