148422597X Kubernetes Management Design Patterns [Vohra 2017-01-29] {E559F6BB}

marco.cirilli
from marco.cirilli More from this publisher
19.06.2021 Views

Chapter 7 ■ Using ServicesDescribe the service:./kubectl describe svc hello-worldThe service description includes the service type as ClusterIP and three endpoints for the service, asshown in Figure 7-6.Figure 7-6. Describing the hello-world serviceThe service may be accessed at the clusterIP and each of the service endpoints. First, access thecluster IP with the command curl cluster-ip. The cluster-ip is 10.3.0.234, so access the service at curl10.3.0.234. The HTML markup for the service is output as shown in Figure 7-7.Figure 7-7. Invoking a service endpoint with curl157

Chapter 7 ■ Using ServicesSimilarly, invoke the service at a service endpoint 10.2.12.7 as shown in Figure 7-8. The HTML markupfor the service is output.Figure 7-8. Invoking a different service endpointTo invoke the service in a web browser, set port forwarding from a local machine. First, copy the keypairused to access the cluster controller instance to the local machine:scp -i docker.pem ec2-user@ec2-107-23-131-161.compute-1.amazonaws.com:~/kubernetes-coreos.pem ~/kubernetes-coreos.pemThen set port forwarding from the local machine locahost:80 to the cluster IP of the service on thecontroller instance:ssh -i kubernetes-coreos.pem -f -nNT -L 80:10.3.0.234:80 core@ec2-52-203-239-87.compute-1.amazonaws.comPort forwarding from local machine localhost:80 to cluster-ip:80 is set. Invoke the service in a webbrowser at http://localhost, as shown in Figure 7-9.158

Chapter 7 ■ Using Services

Describe the service:

./kubectl describe svc hello-world

The service description includes the service type as ClusterIP and three endpoints for the service, as

shown in Figure 7-6.

Figure 7-6. Describing the hello-world service

The service may be accessed at the clusterIP and each of the service endpoints. First, access the

cluster IP with the command curl cluster-ip. The cluster-ip is 10.3.0.234, so access the service at curl

10.3.0.234. The HTML markup for the service is output as shown in Figure 7-7.

Figure 7-7. Invoking a service endpoint with curl

157

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!