- Getting Started with Kubernetes
- Jonathan Baier Jesse White
- 286字
- 2021-06-10 19:47:14
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
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/
- 課課通計算機原理
- Word 2000、Excel 2000、PowerPoint 2000上機指導(dǎo)與練習(xí)
- 計算機控制技術(shù)
- Mastering Elastic Stack
- iClone 4.31 3D Animation Beginner's Guide
- Embedded Programming with Modern C++ Cookbook
- 現(xiàn)代傳感技術(shù)
- ESP8266 Home Automation Projects
- Excel 2010函數(shù)與公式速查手冊
- 人工智能:語言智能處理
- 單片機原理實用教程
- 生物3D打印:從醫(yī)療輔具制造到細胞打印
- 智慧未來
- Cortex-M3嵌入式處理器原理與應(yīng)用
- Data Analysis with R(Second Edition)