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

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/
主站蜘蛛池模板: 宽甸| 崇明县| 花垣县| 进贤县| 建德市| 盐源县| 舞阳县| 怀远县| 南投县| 南乐县| 泾阳县| 南城县| 保康县| 香河县| 石狮市| 德阳市| 连山| 讷河市| 谷城县| 红原县| 齐齐哈尔市| 娱乐| 姜堰市| 紫阳县| 图们市| 苍山县| 西安市| 洞口县| 天全县| 绥阳县| 萨嘎县| 钦州市| 永兴县| 滕州市| 邢台县| 司法| 禄丰县| 恩施市| 太仆寺旗| 阿坝| 内江市|