kubernetes测试实例guestbook 外网访问不了


安装kubernetes后,测试Guestbook Example,就是那个redis实例,想让外网访问guestbook,但是一直访问不了,我用的NodePorts配置,访问http://192.168.199.20:30061/失败,

frontend-service.yaml配置如下:
apiVersion: v1
kind: Service
metadata:
name: frontend
labels:
app: guestbook
tier: frontend
spec:
# if your cluster supports it, uncomment the following to automatically create
# an external load-balanced IP for the frontend service.
type: NodePort
ports:
# the port that this service should serve on
- port: 80
nodePort: 30061
selector:
app: guestbook
tier: frontend

frontend-controller.yaml配置如下:
apiVersion: v1
kind: ReplicationController
metadata:
name: frontend
# these labels can be applied automatically
# from the labels in the pod template if not set
labels:
app: guestbook
tier: frontend
spec:
# this replicas value is default
# modify it according to your case
replicas: 3
# selector can be applied automatically
# from the labels in the pod template if not set
# selector:
# app: guestbook
# tier: frontend
template:
metadata:
labels:
app: guestbook
tier: frontend
spec:
containers:
- name: php-redis
image: examples/guestbook/php-redis
resources:
requests:
cpu: 100m
memory: 100Mi
env:
- name: GET_HOSTS_FROM
value: dns
# If your cluster config does not include a dns service, then to
# instead access environment variables to find service host
# info, comment out the 'value: dns' line above, and uncomment the
# line below.
# value: env
ports:
- containerPort: 80

是我配置那错呢?
已邀请:

master12

赞同来自:


LoadBalancer方式配置不知配置,望求教

master12

赞同来自:


我看文档里有一个LoadBalancer配置方式,但是json格式的,我用的yaml这种配置文档

FindOutWhy

赞同来自:


首先确认你整个创建svc,rc有没有报错,如果没有做如下工作:
<ol><li>确保PodIP:containerPort在集群内是否可以访问?</li><li>ServiceIP:containerPort在集群内是否可以访问?</li><li>NodePort模式会在每个Node上为你的服务暴露一个端口,从你的集群上随机选几个访问NodeIP:nodePort看能不能访问?如果不行,可以通过iptables查看路由规则,看是否正确路由。。我猜测可能是你的Node上没有启动kube-proxy</li><li>如果不想在每个Node上都暴露一个端口给你的服务,端口毕竟还是稀缺资源,可以使用HostPort模式,只在Pod所在的Node上为你的服务暴露一个端口。</li></ol>

要回复问题请先登录注册