我正在我的笔记本电脑(Windows 10 OS)上设置kubernetes,以在容器及其业务流程上工作。 我使用以下命令创建了Minikube VM,并成功完成了
。minikube start --vm-driver hyperv --hyperv-virtual-switch "Primary Virtual Switch"
我能够启动Kubernetes,并且也能够启动Minikube仪表板
我启动了Kubernetes集群,并将nginx应用程序部署到了集群中。下面是命令。
kubectl run hello-nginx --image=nginx --port=8020
kubectl expose deployment hello-nginx --type=NodePort --port=8020 --target-port=8020
我可以使用以下命令查看POD和服务。
kubectl get pods
kubectl get services
它在这里可以完美运行。我可以在Minikube仪表板中查看部署,POD和服务信息。
当我运行以下命令以在浏览器中启动应用程序时,浏览器将显示一条消息“找不到资源”,但我能够在MiniKube仪表板中查看POD和服务信息。
minikube service hello-nginx
URL:http://192.168.43.20:32087/
在浏览器中获取异常
This website could not be found.
Error Code: INET_E_RESOURCE_NOT_FOUND
在给出了部署YAML文件之后,
{
"kind": "Deployment",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": "hello-nginx",
"namespace": "default",
"selfLink": "/apis/extensions/v1beta1/namespaces/default/deployments/hello-nginx",
"uid": "5629038e-93e5-11e9-ad2e-00155d162e0e",
"resourceVersion": "49313",
"generation": 1,
"creationTimestamp": "2019-06-21T05:28:01Z",
"labels": {
"run": "hello-nginx"
},
"annotations": {
"deployment.kubernetes.io/revision": "1"
}
},
"spec": {
"replicas": 1,
"selector": {
"matchLabels": {
"run": "hello-nginx"
}
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"run": "hello-nginx"
}
},
"spec": {
"containers": [
{
"name": "hello-nginx",
"image": "nginx",
"ports": [
{
"containerPort": 8020,
"protocol": "TCP"
}
],
"resources": {},
"terminationMessagePath": "/dev/termination-log",
"terminationMessagePolicy": "File",
"imagePullPolicy": "Always"
}
],
"restartPolicy": "Always",
"terminationGracePeriodSeconds": 30,
"dnsPolicy": "ClusterFirst",
"securityContext": {},
"schedulerName": "default-scheduler"
}
},
"strategy": {
"type": "RollingUpdate",
"rollingUpdate": {
"maxUnavailable": 1,
"maxSurge": 1
}
},
"revisionHistoryLimit": 2147483647,
"progressDeadlineSeconds": 2147483647
},
"status": {
"observedGeneration": 1,
"replicas": 1,
"updatedReplicas": 1,
"readyReplicas": 1,
"availableReplicas": 1,
"conditions": [
{
"type": "Available",
"status": "True",
"lastUpdateTime": "2019-06-21T05:28:01Z",
"lastTransitionTime": "2019-06-21T05:28:01Z",
"reason": "MinimumReplicasAvailable",
"message": "Deployment has minimum availability."
}
]
}
}
在给定副本集YAML文件信息的情况下,
{
"kind": "ReplicaSet",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": "hello-nginx-76696c698f",
"namespace": "default",
"selfLink": "/apis/extensions/v1beta1/namespaces/default/replicasets/hello-nginx-76696c698f",
"uid": "562be1e8-93e5-11e9-ad2e-00155d162e0e",
"resourceVersion": "49310",
"generation": 3,
"creationTimestamp": "2019-06-21T05:28:01Z",
"labels": {
"pod-template-hash": "76696c698f",
"run": "hello-nginx"
},
"annotations": {
"deployment.kubernetes.io/desired-replicas": "1",
"deployment.kubernetes.io/max-replicas": "2",
"deployment.kubernetes.io/revision": "1"
},
"ownerReferences": [
{
"apiVersion": "apps/v1",
"kind": "Deployment",
"name": "hello-nginx",
"uid": "5629038e-93e5-11e9-ad2e-00155d162e0e",
"controller": true,
"blockOwnerDeletion": true
}
]
},
"spec": {
"replicas": 1,
"selector": {
"matchLabels": {
"pod-template-hash": "76696c698f",
"run": "hello-nginx"
}
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"pod-template-hash": "76696c698f",
"run": "hello-nginx"
}
},
"spec": {
"containers": [
{
"name": "hello-nginx",
"image": "nginx",
"ports": [
{
"containerPort": 8020,
"protocol": "TCP"
}
],
"resources": {},
"terminationMessagePath": "/dev/termination-log",
"terminationMessagePolicy": "File",
"imagePullPolicy": "Always"
}
],
"restartPolicy": "Always",
"terminationGracePeriodSeconds": 30,
"dnsPolicy": "ClusterFirst",
"securityContext": {},
"schedulerName": "default-scheduler"
}
}
},
"status": {
"replicas": 1,
"fullyLabeledReplicas": 1,
"readyReplicas": 1,
"availableReplicas": 1,
"observedGeneration": 3
}
}
现在,我正在尝试“端口转发”选项,以将请求路由到POD,但是它不起作用。
kubectl port-forward deployment/hello-nginx 8020:8020
当我尝试访问URL“ http://127.0.0.1:8020”
时,出现以下异常Handling connection for 8020
E0622 01:07:06.306320 18888 portforward.go:331] an error occurred forwarding 8020 -> 8020: error forwarding port 8020 to pod c54d6faaa545992dce02f58490a26154134843eb7426a51e78df2cda172b514c, uid : exit status 1: 2019/06/21 08:01:18 socat[4535] E connect(5, AF=2 127.0.0.1:8020, 16): Connection refused
我已经阅读了许多有关此问题的文章,但找不到此问题的根本原因。我在这里错过任何重要的东西吗?
感谢您对Advance的帮助。
答案 0 :(得分:1)
您的问题实际上与Minikube或端口转发无关。您公开了端口8020
,但是应用程序hello-nginx
使用80
。因此,您应该在各处使用80
而不是8020
。例如:
kubectl run hello-nginx --image=nginx --port=80
说,对于Windows,使用Minikube不是最佳选择。更好的方法是使用Docker Desktop,然后在localhost
上可以使用在Kubernetes上运行的所有内容。