- 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/
- 工業機器人技術及應用
- 腦動力:C語言函數速查效率手冊
- 計算機應用基礎·基礎模塊
- 西門子PLC與InTouch綜合應用
- 手把手教你學AutoCAD 2010
- 大型數據庫管理系統技術、應用與實例分析:SQL Server 2005
- Arduino &樂高創意機器人制作教程
- Chef:Powerful Infrastructure Automation
- 中國戰略性新興產業研究與發展·智能制造裝備
- 手機游戲程序開發
- 大數據技術基礎:基于Hadoop與Spark
- 從零開始學PHP
- 水晶石影視動畫精粹:After Effects & Nuke 影視后期合成
- INSTANT VMware vCloud Starter
- WOW!Photoshop CS6完全自學寶典