[英]Cannot access kubernetes service via outside network
I setup kubernetes environment with kubernetes 1.3.0, and running master and node on same host, I run a tomcat web application with one RC, one Service with docker, all seems running fine, I can access the service via internal network with curl command, but when I try to access the Service from Internet with public IP, it is failure. 我用kubernetes 1.3.0设置kubernetes环境,并在同一主机上运行master和node,我运行一个带有一个RC的tomcat web应用程序,一个带docker的服务,一切运行正常,我可以通过curl命令通过内部网络访问服务,但是当我尝试使用公共IP从Internet访问服务时,它就失败了。
The RC configure is: RC配置是:
apiVersion: v1
kind: ReplicationController
metadata:
name: myweb
spec:
replicas: 2
selector:
app: myweb
template:
metadata:
labels:
app: myweb
spec:
containers:
- name: myweb
image: kubeguide/tomcat-app:v1
ports:
- containerPort: 8080
env:
- name: MYSQL_SERVICE_HOST
value: "mysql"
- name: MYSQL_SERVICE_PORT
value: '3306'
The Service configure is: 服务配置是:
apiVersion: v1
kind: Service
metadata:
name: myweb
spec:
type: NodePort
ports:
- port: 8080
nodePort: 30001
selector:
app: myweb
As you see, the Service listen the 30001 Port, when the port listen by Kubernetes Service, it cannot be accessed via Internet, but when I use nc -l 30001
command on same host, it can be accessed via Internet, so that means the networking configure is fine on system layer. 如你所见,服务监听30001端口,当端口监听Kubernetes服务时,它无法通过Internet访问,但是当我在同一主机上使用
nc -l 30001
命令时,它可以通过Internet访问,这意味着网络配置在系统层上很好。
For the iptables setting of host, I accept all connections, but the issue is still appeared. 对于主机的iptables设置,我接受所有连接,但问题仍然存在。
then why can I access it with kubernetes service? 那为什么我可以用kubernetes服务访问它? is there any configure I miss?
有什么配置我想念?
To expose the kubernetes service using the host network you can use Ingress rules. 要使用主机网络公开kubernetes服务,您可以使用Ingress规则。
please refer: https://kubernetes.io/docs/concepts/services-networking/ingress/ 请参考: https : //kubernetes.io/docs/concepts/services-networking/ingress/
In your case the ingress rule will be as follows. 在您的情况下,入口规则如下。
apiVersion: extensions/v1beta1 kind: Ingress metadata: name: nginx-test spec: rules: - host: test.example.com http: paths: - backend: serviceName: myweb servicePort: 30001 path: /
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.