【发布时间】:2020-04-07 18:36:31
【问题描述】:
我已经安装了以下:
docker 版本 19.03.8,minikube 版本 1.8.2,kubectl 版本 1.15.5。
并创建了一个如下所示的部署 YAML 文件:
---
kind: Service
apiVersion: v1
metadata:
name: hellowworldservice
spec:
selector:
app: hello-world
ports:
- protocol: "TCP"
# Port accessible inside cluster
port: 8081
# Port to forward to inside the pod
targetPort: 8080
# Port accessible outside cluster
nodePort: 30005
type: LoadBalancer
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-world
labels:
app: hello-world
spec:
replicas: 5
selector:
matchLabels:
app: hello-world
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-world
image: tutum/hello-world
ports:
- containerPort: 8080
pod 和部署成功启动:
PS C:\kubernetes> kubectl create -f deployment.yaml
service/hellowworldservice created
deployment.apps/hello-world created
PS C:\kubernetes> kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-world-889b5c84c-98vvx 1/1 Running 0 25s
hello-world-889b5c84c-bs48d 1/1 Running 0 25s
hello-world-889b5c84c-hm6j2 1/1 Running 0 25s
hello-world-889b5c84c-hzqcc 1/1 Running 0 25s
hello-world-889b5c84c-xg5nl 1/1 Running 0 25s
PS C:\kubernetes> kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
hello-world 5/5 5 5 40s
我可以通过 ping 访问 IP 地址,但不能通过“Hello World”网页应该所在的端口。这是为什么呢?
PS C:\kubernetes> minikube ip
172.17.45.76
PS C:\kubernetes> ping 172.17.45.76
Pinging 172.17.45.76 with 32 bytes of data:
Reply from 172.17.45.76: bytes=32 time<1ms TTL=64
Reply from 172.17.45.76: bytes=32 time<1ms TTL=64
Reply from 172.17.45.76: bytes=32 time<1ms TTL=64
Reply from 172.17.45.76: bytes=32 time=1ms TTL=64
Ping statistics for 172.17.45.76:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 1ms, Average = 0ms
PS C:\kubernetes> curl http://172.17.45.76:30005
curl : Unable to connect to the remote server
At line:1 char:1
+ curl http://172.17.45.76:30005
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
【问题讨论】:
标签: docker kubernetes microservices kubectl minikube