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

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:

Internal service listing

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.

主站蜘蛛池模板: 哈密市| 龙胜| 宁夏| 白朗县| 河间市| 乌兰浩特市| 元江| 额尔古纳市| 上虞市| 石家庄市| 云霄县| 宁安市| 尉氏县| 牡丹江市| 南和县| 汾西县| 合山市| 关岭| 昌乐县| 年辖:市辖区| 榆中县| 竹山县| 吉木萨尔县| 昌黎县| 宁国市| 枝江市| 资溪县| 东台市| 饶阳县| 嵩明县| 即墨市| 高雄市| 白沙| 巢湖市| 常德市| 巴东县| 张北县| 徐闻县| 宜川县| 连山| 巴彦淖尔市|