add code formatting to commands in expose-external-ip-address tutorial
parent
dcd16d57fa
commit
2abce40d08
|
@ -9,12 +9,8 @@ weight: 10
|
||||||
This page shows how to create a Kubernetes Service object that exposes an
|
This page shows how to create a Kubernetes Service object that exposes an
|
||||||
external IP address.
|
external IP address.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## {{% heading "prerequisites" %}}
|
## {{% heading "prerequisites" %}}
|
||||||
|
|
||||||
|
|
||||||
* Install [kubectl](/docs/tasks/tools/install-kubectl/).
|
* Install [kubectl](/docs/tasks/tools/install-kubectl/).
|
||||||
|
|
||||||
* Use a cloud provider like Google Kubernetes Engine or Amazon Web Services to
|
* Use a cloud provider like Google Kubernetes Engine or Amazon Web Services to
|
||||||
|
@ -25,19 +21,12 @@ external IP address.
|
||||||
* Configure `kubectl` to communicate with your Kubernetes API server. For
|
* Configure `kubectl` to communicate with your Kubernetes API server. For
|
||||||
instructions, see the documentation for your cloud provider.
|
instructions, see the documentation for your cloud provider.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## {{% heading "objectives" %}}
|
## {{% heading "objectives" %}}
|
||||||
|
|
||||||
|
|
||||||
* Run five instances of a Hello World application.
|
* Run five instances of a Hello World application.
|
||||||
* Create a Service object that exposes an external IP address.
|
* Create a Service object that exposes an external IP address.
|
||||||
* Use the Service object to access the running application.
|
* Use the Service object to access the running application.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- lessoncontent -->
|
<!-- lessoncontent -->
|
||||||
|
|
||||||
## Creating a service for an application running in five pods
|
## Creating a service for an application running in five pods
|
||||||
|
@ -50,7 +39,6 @@ external IP address.
|
||||||
kubectl apply -f https://k8s.io/examples/service/load-balancer-example.yaml
|
kubectl apply -f https://k8s.io/examples/service/load-balancer-example.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
The preceding command creates a
|
The preceding command creates a
|
||||||
{{< glossary_tooltip text="Deployment" term_id="deployment" >}}
|
{{< glossary_tooltip text="Deployment" term_id="deployment" >}}
|
||||||
and an associated
|
and an associated
|
||||||
|
@ -61,26 +49,36 @@ The preceding command creates a
|
||||||
|
|
||||||
1. Display information about the Deployment:
|
1. Display information about the Deployment:
|
||||||
|
|
||||||
|
```shell
|
||||||
kubectl get deployments hello-world
|
kubectl get deployments hello-world
|
||||||
kubectl describe deployments hello-world
|
kubectl describe deployments hello-world
|
||||||
|
```
|
||||||
|
|
||||||
1. Display information about your ReplicaSet objects:
|
1. Display information about your ReplicaSet objects:
|
||||||
|
|
||||||
|
```shell
|
||||||
kubectl get replicasets
|
kubectl get replicasets
|
||||||
kubectl describe replicasets
|
kubectl describe replicasets
|
||||||
|
```
|
||||||
|
|
||||||
1. Create a Service object that exposes the deployment:
|
1. Create a Service object that exposes the deployment:
|
||||||
|
|
||||||
|
```shell
|
||||||
kubectl expose deployment hello-world --type=LoadBalancer --name=my-service
|
kubectl expose deployment hello-world --type=LoadBalancer --name=my-service
|
||||||
|
```
|
||||||
|
|
||||||
1. Display information about the Service:
|
1. Display information about the Service:
|
||||||
|
|
||||||
|
```shell
|
||||||
kubectl get services my-service
|
kubectl get services my-service
|
||||||
|
```
|
||||||
|
|
||||||
The output is similar to this:
|
The output is similar to this:
|
||||||
|
|
||||||
|
```
|
||||||
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
|
||||||
my-service LoadBalancer 10.3.245.137 104.198.205.71 8080/TCP 54s
|
my-service LoadBalancer 10.3.245.137 104.198.205.71 8080/TCP 54s
|
||||||
|
```
|
||||||
|
|
||||||
{{< note >}}
|
{{< note >}}
|
||||||
|
|
||||||
|
@ -96,10 +94,13 @@ The preceding command creates a
|
||||||
|
|
||||||
1. Display detailed information about the Service:
|
1. Display detailed information about the Service:
|
||||||
|
|
||||||
|
```shell
|
||||||
kubectl describe services my-service
|
kubectl describe services my-service
|
||||||
|
```
|
||||||
|
|
||||||
The output is similar to this:
|
The output is similar to this:
|
||||||
|
|
||||||
|
```
|
||||||
Name: my-service
|
Name: my-service
|
||||||
Namespace: default
|
Namespace: default
|
||||||
Labels: app.kubernetes.io/name=load-balancer-example
|
Labels: app.kubernetes.io/name=load-balancer-example
|
||||||
|
@ -113,6 +114,7 @@ The preceding command creates a
|
||||||
Endpoints: 10.0.0.6:8080,10.0.1.6:8080,10.0.1.7:8080 + 2 more...
|
Endpoints: 10.0.0.6:8080,10.0.1.6:8080,10.0.1.7:8080 + 2 more...
|
||||||
Session Affinity: None
|
Session Affinity: None
|
||||||
Events: <none>
|
Events: <none>
|
||||||
|
```
|
||||||
|
|
||||||
Make a note of the external IP address (`LoadBalancer Ingress`) exposed by
|
Make a note of the external IP address (`LoadBalancer Ingress`) exposed by
|
||||||
your service. In this example, the external IP address is 104.198.205.71.
|
your service. In this example, the external IP address is 104.198.205.71.
|
||||||
|
@ -124,21 +126,27 @@ The preceding command creates a
|
||||||
addresses of the pods that are running the Hello World application. To
|
addresses of the pods that are running the Hello World application. To
|
||||||
verify these are pod addresses, enter this command:
|
verify these are pod addresses, enter this command:
|
||||||
|
|
||||||
|
```shell
|
||||||
kubectl get pods --output=wide
|
kubectl get pods --output=wide
|
||||||
|
```
|
||||||
|
|
||||||
The output is similar to this:
|
The output is similar to this:
|
||||||
|
|
||||||
|
```
|
||||||
NAME ... IP NODE
|
NAME ... IP NODE
|
||||||
hello-world-2895499144-1jaz9 ... 10.0.1.6 gke-cluster-1-default-pool-e0b8d269-1afc
|
hello-world-2895499144-1jaz9 ... 10.0.1.6 gke-cluster-1-default-pool-e0b8d269-1afc
|
||||||
hello-world-2895499144-2e5uh ... 10.0.1.8 gke-cluster-1-default-pool-e0b8d269-1afc
|
hello-world-2895499144-2e5uh ... 10.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-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-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
|
hello-world-2895499144-segjf ... 10.0.2.5 gke-cluster-1-default-pool-e0b8d269-cpuc
|
||||||
|
```
|
||||||
|
|
||||||
1. Use the external IP address (`LoadBalancer Ingress`) to access the Hello
|
1. Use the external IP address (`LoadBalancer Ingress`) to access the Hello
|
||||||
World application:
|
World application:
|
||||||
|
|
||||||
|
```shell
|
||||||
curl http://<external-ip>:<port>
|
curl http://<external-ip>:<port>
|
||||||
|
```
|
||||||
|
|
||||||
where `<external-ip>` is the external IP address (`LoadBalancer Ingress`)
|
where `<external-ip>` is the external IP address (`LoadBalancer Ingress`)
|
||||||
of your Service, and `<port>` is the value of `Port` in your Service
|
of your Service, and `<port>` is the value of `Port` in your Service
|
||||||
|
@ -148,29 +156,27 @@ The preceding command creates a
|
||||||
|
|
||||||
The response to a successful request is a hello message:
|
The response to a successful request is a hello message:
|
||||||
|
|
||||||
|
```shell
|
||||||
Hello Kubernetes!
|
Hello Kubernetes!
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## {{% heading "cleanup" %}}
|
## {{% heading "cleanup" %}}
|
||||||
|
|
||||||
|
|
||||||
To delete the Service, enter this command:
|
To delete the Service, enter this command:
|
||||||
|
|
||||||
|
```shell
|
||||||
kubectl delete services my-service
|
kubectl delete services my-service
|
||||||
|
```
|
||||||
|
|
||||||
To delete the Deployment, the ReplicaSet, and the Pods that are running
|
To delete the Deployment, the ReplicaSet, and the Pods that are running
|
||||||
the Hello World application, enter this command:
|
the Hello World application, enter this command:
|
||||||
|
|
||||||
|
```shell
|
||||||
kubectl delete deployment hello-world
|
kubectl delete deployment hello-world
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## {{% heading "whatsnext" %}}
|
## {{% heading "whatsnext" %}}
|
||||||
|
|
||||||
|
|
||||||
Learn more about
|
Learn more about
|
||||||
[connecting applications with services](/docs/concepts/services-networking/connect-applications-service/).
|
[connecting applications with services](/docs/concepts/services-networking/connect-applications-service/).
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue