docker - 无法在 kubernetes minikube 上访问 IP 和 PORT
问题描述
我在 kubernetes 上创建了 Web 部署和服务当我使用$ kubectl get service
命令列出服务以列出 IP 和端口以访问网页但当我尝试访问它时无法访问该站点。似乎 minikube 上的 kubernetes 没有从 docker hub 拉取图像。
这是我的示例脚本。我使用 Kubernetes v1.19.2 和默认驱动程序 Docker 19.03.8
$ kubectl create -f web-pets.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: web spec: replicas: 1 selector: matchLabels: app: pets service: web template: metadata: labels: app: pets service: web spec: containers: - image: nginx:alpine-1.19.2 name: web ports: - containerPort: 80 protocol: TCP --- apiVersion: v1 kind: Service metadata: name: web spec: type: NodePort ports: - port: 80 protocol: TCP selector: app: pets service: web
- 输出创建
web-pets.yaml
$ kubectl create -f web-pets.yaml deployment.apps/web created service/web created
- 输出
$ kubectl get service
$ kubectl get service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 11h web NodePort 10.110.107.234 <none> 80:30100/TCP 41s
- 输出
$ kubectl get service web
Name: web Namespace: default Labels: <none> Annotations: <none> Selector: app=pets,service=web Type: NodePort IP: 10.109.10.68 Port: <unset> 3000/TCP TargetPort: 3000/TCP NodePort: <unset> 31830/TCP Endpoints: <none> Session Affinity: None External Traffic Policy: Cluster Events: <none>
- 当列出所有 docker 镜像时没有 nginx 镜像
$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE kicbase/stable v0.0.12-snapshot3 25ac91b9c8d7 4 weeks ago 952MB gcr.io/k8s-minikube/kicbase v0.0.12-snapshot3 25ac91b9c8d7 4 weeks ago 952MB
- 部署网页描述
$ kubectl describe deploy web Name: web Namespace: default CreationTimestamp: Thu, 24 Sep 2020 17:25:42 +0700 Labels: <none> Annotations: <none> Selector: app=pets,service=web Replicas: 1 desired | 0 updated | 0 total | 0 available | 0 unavailable StrategyType: RollingUpdate MinReadySeconds: 0 RollingUpdateStrategy: 25% max unavailable, 25% max surge Pod Template: Labels: app=pets service=web Containers: web: Image: nginx:alpine-1.19.2 Port: 3000/TCP Host Port: 0/TCP Environment: <none> Mounts: <none> Volumes: <none> OldReplicaSets: <none> NewReplicaSet: <none> Events: <none>
$ kubectl get pods
$ kubectl get pods No resources found in default namespace.
$ kubectl get events
LAST SEEN TYPE REASON OBJECT MESSAGE 7m13s Normal Starting node/minikube Starting kubelet. 7m11s Normal NodeHasSufficientMemory node/minikube Node minikube status is now: NodeHasSufficientMemory 7m11s Normal NodeHasNoDiskPressure node/minikube Node minikube status is now: NodeHasNoDiskPressure 7m11s Normal NodeHasSufficientPID node/minikube Node minikube status is now: NodeHasSufficientPID 7m12s Normal NodeAllocatableEnforced node/minikube Updated Node Allocatable limit across pods 6m28s Normal Starting node/minikube Starting kube-proxy.
解决方案
Nginx 监听端口80
。因此,您需要在部署和服务中使用端口80
而不是端口。3000
从文档中,您应该可以使用
minikube service web
推荐阅读
- c# - 如何生成静态文件的 URL(就像 ASP.NET Core UrlHelper 为操作方法所做的那样)?
- laravel - 使用 vuejs 和 laravel 上传文件
- javascript - 如何从响应中设置环境变量,其中包括 # 和 -
- javascript - postman.setNextRequest 无法正常工作
- html - 无法在字段中心移动标签
- typescript - 拆分 TypeScript d.ts 文件的现代方法
- xamarin - Stacklayout 上所有 3 个平台(Android、iOS、UWP)中的 Xamarin 长按事件
- hyperledger-fabric - Hyperledger 中的排序服务如何生成块
- python - Python为数据框中每组的前3个值选择数据
- laravel - 如何在 Laravel 5.7 Multiple Guards 上验证电子邮件?