diff --git a/_data/tutorials.yml b/_data/tutorials.yml index e312523bcd..01440b09d7 100644 --- a/_data/tutorials.yml +++ b/_data/tutorials.yml @@ -48,3 +48,5 @@ toc: path: /docs/tutorials/stateless-application/run-stateless-application-deployment/ - title: Using a Service to Access an Application in a Cluster path: /docs/tutorials/stateless-application/expose-external-ip-address-service/ + - title: Exposing an External IP Address to Access an Application in a Cluster + path: /docs/tutorials/stateless-application/expose-external-ip-address/ diff --git a/docs/tutorials/index.md b/docs/tutorials/index.md index 03ae95fe36..14530ca25e 100644 --- a/docs/tutorials/index.md +++ b/docs/tutorials/index.md @@ -13,6 +13,8 @@ The Tutorials section of the Kubernetes documentation is a work in progress. * [Using a Service to Access an Application in a Cluster](/docs/tutorials/stateless-application/expose-external-ip-address-service/) +* [Exposing an External IP Address to Access an Application in a Cluster](/docs/tutorials/stateless-application/expose-external-ip-address/) + ### What's next If you would like to write a tutorial, see diff --git a/docs/tutorials/stateless-application/expose-external-ip-address.md b/docs/tutorials/stateless-application/expose-external-ip-address.md new file mode 100644 index 0000000000..63aabb813d --- /dev/null +++ b/docs/tutorials/stateless-application/expose-external-ip-address.md @@ -0,0 +1,153 @@ +--- +--- + +{% capture overview %} + +This page shows how to create a Kubernetes Service object that exposees an +external IP address. + +{% endcapture %} + + +{% capture prerequisites %} + +* Install [kubectl](http://kubernetes.io/docs/user-guide/prereqs). + +* Use a cloud provider like Google Container Engine or Amazon Web Services to + create a Kubernetes cluster. This tutorial creates an + [external load balancer](/docs/user-guide/load-balancer/), + which requires a cloud provider. + +* Configure `kubectl` to communicate with your Kubernetes API server. For + instructions, see the documentation for your cloud provider. + +{% endcapture %} + + +{% capture objectives %} + +* Run five instances of a Hello World application. +* Create a Service object that exposes an external IP address. +* Use the Service object to access the running application. + +{% endcapture %} + + +{% capture lessoncontent %} + +### Creating a service for an application running in five pods + +1. Run a Hello World application in your cluster: + + kubectl run hello-world --replicas=5 --labels="run=load-balancer-example" --image=gcr.io/google-samples/node-hello:1.0 --port=8080 + + The preceding command creates a + [Deployment](/docs/user-guide/deployments/) + object and an associated + [ReplicaSet](/docs/user-guide/replicasets/) + object. The ReplicaSet has five + [Pods](/docs/user-guide/pods/), + each of which runs the Hello World application. + +1. Display information about the Deployment: + + kubectl get deployments hello-world + kubectl describe deployments hello-world + +1. Display information about your ReplicaSet objects: + + kubectl get replicasets + kubectl describe replicasets + +1. Create a Service object that exposes the deployment: + + kubectl expose deployment hello-world --type=LoadBalancer --name=my-service + +1. Display information about the Service: + + kubectl get services my-service + + The output is similar to this: + + NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE + my-service 10.3.245.137 104.198.205.71 8080/TCP 54s + + Note: If the external IP address is shown as , wait for a minute + and enter the same command again. + +1. Display detailed information about the Service: + + kubectl describe services my-service + + The output is similar to this: + + Name: my-service + Namespace: default + Labels: run=load-balancer-example + Selector: run=load-balancer-example + Type: LoadBalancer + IP: 10.3.245.137 + LoadBalancer Ingress: 104.198.205.71 + Port: 8080/TCP + NodePort: 32377/TCP + Endpoints: 10.0.0.6:8080,10.0.1.6:8080,10.0.1.7:8080 + 2 more... + Session Affinity: None + Events: + + Make a note of the external IP address exposed by your service. In this + example, the external IP address is 104.198.205.71. Also note + the value of Port. In this example, the port is 8080. + +1. In the preceding output, you can see that the service has several endpoints: + 10.0.0.6:8080,10.0.1.6:8080,10.0.1.7:8080 + 2 more. These are internal + addresses of the pods that are running the Hello World application. To + verify these are pod addresses, enter this command: + + kubectl get pods --output=wide + + The output is similar to this: + + NAME ... IP NODE + hello-world-2895499144-1jaz9 ... 10.0.1.6 gke-cluster-1-default-pool-e0b8d269-1afc + hello-world-2895499144-2e5uh ... 0.0.1.8 gke-cluster-1-default-pool-e0b8d269-1afc + hello-world-2895499144-9m4h1 ... 10.0.0.6 gke-cluster-1-default-pool-e0b8d269-5v7a + hello-world-2895499144-o4z13 ... 10.0.1.7 gke-cluster-1-default-pool-e0b8d269-1afc + hello-world-2895499144-segjf ... 10.0.2.5 gke-cluster-1-default-pool-e0b8d269-cpuc + +1. Use the external IP address to access the Hello World application: + + curl http://: + + where `` us the external IP address of your Service, + and `` is the value of `Port` in your Service description. + + The response to a successful request is a hello message: + + Hello Kubernetes! + +{% endcapture %} + + +{% capture cleanup %} + +To delete the Service, enter this command: + + kubectl delete services my-service + +To delete the Deployment, the ReplicaSet, and the Pods that are running +the Hello World application, enter this command: + + kubectl delete deployment hello-world + +{% endcapture %} + + +{% capture whatsnext %} + +Learn more about +[connecting applications with services](/docs/user-guide/connecting-applications/). +{% endcapture %} + +{% include templates/tutorial.md %} + +