Google 容器连接到服务
Google container connect to service
我正在学习 PluralSight 上的课程,课程作者将 docker 图像放到 kubernetes 上,然后通过他的浏览器访问它。我正在尝试复制他所做的事情,但我无法访问该网站。我想我可能连接到了错误的 IP。
我有一个 ReplicationController
那是 运行 10 pods
:
rc.yml
apiVersion: v1
kind: ReplicationController
metadata:
name: hello-rc
spec:
replicas: 10
selector:
app: hello-world
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-pod
image: nigelpoulton/pluralsight-docker-ci:latest
ports:
- containerPort: 8080
然后我尝试公开 rc:
kubectl expose rc hello-rc --name=hello-svc --target-port=8080 --type=NodePort
$ kubectl get services
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-svc 10.27.254.160 <nodes> 8080:30488/TCP 30s
kubernetes 10.27.240.1 <none> 443/TCP 1h
我的 google 容器端点是:35.xxx.xx.xxx
并且当 运行 kubectl describe svc hello-svc
时,NodePort 是 30488
因此我尝试在 35.xxx.xx.xxx:30488
访问该应用程序,但无法访问该站点。
如果您想通过 NodePort 端口访问您的服务,您需要为该端口(和该实例)打开防火墙。
更好的方法是创建一个类型为 LoadBalancer (--type=LoadBalancer
) 的服务并在 Google 给你的 IP 上访问它。
完成后不要忘记删除负载均衡器。
我正在学习 PluralSight 上的课程,课程作者将 docker 图像放到 kubernetes 上,然后通过他的浏览器访问它。我正在尝试复制他所做的事情,但我无法访问该网站。我想我可能连接到了错误的 IP。
我有一个 ReplicationController
那是 运行 10 pods
:
rc.yml
apiVersion: v1
kind: ReplicationController
metadata:
name: hello-rc
spec:
replicas: 10
selector:
app: hello-world
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-pod
image: nigelpoulton/pluralsight-docker-ci:latest
ports:
- containerPort: 8080
然后我尝试公开 rc:
kubectl expose rc hello-rc --name=hello-svc --target-port=8080 --type=NodePort
$ kubectl get services
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-svc 10.27.254.160 <nodes> 8080:30488/TCP 30s
kubernetes 10.27.240.1 <none> 443/TCP 1h
我的 google 容器端点是:35.xxx.xx.xxx
并且当 运行 kubectl describe svc hello-svc
时,NodePort 是 30488
因此我尝试在 35.xxx.xx.xxx:30488
访问该应用程序,但无法访问该站点。
如果您想通过 NodePort 端口访问您的服务,您需要为该端口(和该实例)打开防火墙。
更好的方法是创建一个类型为 LoadBalancer (--type=LoadBalancer
) 的服务并在 Google 给你的 IP 上访问它。
完成后不要忘记删除负载均衡器。