Difference and significance nodePort, targetPort, port of Kubernetes in

1. nodePort
 port accessible outside the machine.
For example, a Web application needs to be accessed by other users, you need to configure the type = NodePort, and the configuration nodePort = 30001, then the other machines can access scheme through the browser: // node: 30001 Access to the service, such as http: // node : 30001.
 Such as MySQL database may be accessed by the outside world does not need, just to be internal service access, you do not need to set NodePort

2. targetPort
 port container (fundamental inlet port), consistent with the port (DockerFile the EXPOSE) exposed in the production of containers, e.g. docker.io official nginx port 80 is exposed.
 docker.io official nginx container DockerFile reference https://github.com/nginxinc/docker-nginx

3. port
 port access between kubernetes in services, although mysql exposed container port 3306 (refer https://github.com/docker-library/mysql/ of DockerFile), but other cluster container needs access through port 33306 the service, the external device can not access mysql service, because he did not have the type of configuration NodePort

Example 4

 

apiVersion: v1
kind: Service
metadata:
 name: nginx-service
spec:
 type: NodePort
 ports:
 - port: 30080
   targetPort: 80
   nodePort: 30001
 selector:
  name: nginx-pod

 

apiVersion: v1
kind: Service
metadata:
 name: mysql-service
spec:
 ports:
 - port: 33306
   targetPort: 3306
 selector:
  name: mysql-pod

 

Reference:
https://blog.csdn.net/u013760355/article/details/70162242

Guess you like

Origin www.cnblogs.com/sandshell/p/11685973.html