- Getting Started with Kubernetes
- Jonathan Baier Jesse White
- 312字
- 2021-06-10 19:47:13
Internal services
Let's explore the other types of services that we can deploy. First, by default, services are only internally facing. You can specify a type of clusterIP to achieve this, but, if no type is defined, clusterIP is the assumed type. Let's take a look at an example, nodejs-service-internal.yaml; note the lack of the type element:
apiVersion: v1
kind: Service
metadata:
name: node-js-internal
labels:
name: node-js-internal
spec:
ports:
- port: 80
selector:
name: node-js
Use this listing to create the service definition file. You'll need a healthy version of the node-js RC (Listing nodejs-health-controller-2.yaml). As you can see, the selector matches on the pods named node-js that our RC launched in the previous chapter. We will create the service and then list the currently running services with a filter as follows:
$ kubectl create -f nodejs-service-internal.yaml
$ kubectl get services -l name=node-js-internal
The following screenshot is the result of the preceding command:

As you can see, we have a new service, but only one IP. Furthermore, the IP address is not externally accessible. We won't be able to test the service from a web browser this time. However, we can use the handy kubectl exec command and attempt to connect from one of the other pods. You will need node-js-pod (nodejs-pod.yaml) running. Then, you can execute the following command:
$ kubectl exec node-js-pod -- curl <node-js-internal IP>
This allows us to run a docker exec command as if we had a shell in the node-js-pod container. It then hits the internal service URL, which forwards to any pods with the node-js label.
If all is well, you should get the raw HTML output back. You have successfully created an internal-only service. This can be useful for backend services that you want to make available to other containers running in your cluster, but not open to the world at large.
- PowerShell 3.0 Advanced Administration Handbook
- Mastering D3.js
- Security Automation with Ansible 2
- 人工智能工程化:應用落地與中臺構建
- SharePoint 2010開發最佳實踐
- 西門子S7-200 SMART PLC實例指導學與用
- 數據通信與計算機網絡
- Statistics for Data Science
- 網絡存儲·數據備份與還原
- 在實戰中成長:C++開發之路
- 基于敏捷開發的數據結構研究
- 教育創新與創新人才:信息技術人才培養改革之路(四)
- 玩轉PowerPoint
- Hands-On Generative Adversarial Networks with Keras
- ORACLE數據庫技術實用詳解