官术网_书友最值得收藏!

Custom ports

Services also allow you to map your traffic to different ports; then, the containers and pods expose themselves. We will create a service that exposes port 90 and forwards traffic to port 80 on the pods. We will call the node-js-90 pod to reflect the custom port number. Create the following two definition files, nodejs-customPort-controller.yaml and nodejs-customPort-service.yaml:

apiVersion: v1 
kind: ReplicationController
metadata:
name: node-js-90
labels:
name: node-js-90
spec:
replicas: 3
selector:
name: node-js-90
template:
metadata:
labels:
name: node-js-90
spec:
containers:
- name: node-js-90
image: jonbaier/node-express-info:latest
ports:
- containerPort: 80
apiVersion: v1 
kind: Service
metadata:
name: node-js-90
labels:
name: node-js-90
spec:
type: LoadBalancer
ports:
- port: 90
targetPort: 80
selector:
name: node-js-90
If you are using the free trial for Google Cloud Platform, you may have issues with the LoadBalancer type services. This type creates multiple external IP addresses, but trial accounts are limited to only one static address.

You'll note that in the service definition, we have a targetPort element. This element tells the service the port to use for pods/containers in the pool. As we saw in previous examples, if you do not specify targetPort, it assumes that it's the same port as the service. This port is still used as the service port, but, in this case, we are going to expose the service on port 90 while the containers serve content on port 80.

Create this RC and service and open the appropriate firewall rules, as we did in the last example. It may take a moment for the external load balancer IP to propagate to the get service command. Once it does, you should be able to open and see our familiar web application in a browser using the following format:

http://<external service IP>:90/
主站蜘蛛池模板: 三门县| 百色市| 札达县| 手游| 海门市| 巴中市| 甘德县| 句容市| 弥勒县| 施秉县| 秀山| 吴桥县| 巴彦县| 嘉禾县| 乐安县| 丹凤县| 垫江县| 萨迦县| 会东县| 宜宾县| 永德县| 化州市| 漳浦县| 上犹县| 大安市| 新和县| 威信县| 中牟县| 太仆寺旗| 张家口市| 巴彦淖尔市| 渭源县| 德阳市| 仪陇县| 宁化县| 清河县| 钦州市| 嘉义市| 盐源县| 涿州市| 长兴县|