Update service-access-application-cluster.md (#8699)
* Update service-access-application-cluster.md Fix code snippet formatting and indentation in ordered list (#8698) * Fixes code formatting using code fences Here's a pass with code fences. It seems to work well, and I indented the code fences in the source for readability, even though it wasn't needed for proper indentation in the rendered output. I wasn't able to use code fences and get the text "The response to a successful request is a hello message:" on its own line. I can achieve that using indentation, but for consistency's sake I used the code fences and placed the text with the paragraph above it. * Adds `shell` to the code fencespull/8765/head
parent
b4b3ad2bc7
commit
83d9cef8a9
|
@ -34,9 +34,9 @@ provides load balancing for an application that has two running instances.
|
||||||
## Creating a service for an application running in two pods
|
## Creating a service for an application running in two pods
|
||||||
|
|
||||||
1. Run a Hello World application in your cluster:
|
1. Run a Hello World application in your cluster:
|
||||||
|
```shell
|
||||||
kubectl run hello-world --replicas=2 --labels="run=load-balancer-example" --image=gcr.io/google-samples/node-hello:1.0 --port=8080
|
kubectl run hello-world --replicas=2 --labels="run=load-balancer-example" --image=gcr.io/google-samples/node-hello:1.0 --port=8080
|
||||||
|
```
|
||||||
The preceding command creates a
|
The preceding command creates a
|
||||||
[Deployment](/docs/concepts/workloads/controllers/deployment/)
|
[Deployment](/docs/concepts/workloads/controllers/deployment/)
|
||||||
object and an associated
|
object and an associated
|
||||||
|
@ -46,77 +46,81 @@ provides load balancing for an application that has two running instances.
|
||||||
each of which runs the Hello World application.
|
each of which runs the Hello World application.
|
||||||
|
|
||||||
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=NodePort --name=example-service
|
kubectl expose deployment hello-world --type=NodePort --name=example-service
|
||||||
|
```
|
||||||
|
|
||||||
1. Display information about the Service:
|
1. Display information about the Service:
|
||||||
|
```shell
|
||||||
kubectl describe services example-service
|
kubectl describe services example-service
|
||||||
|
```
|
||||||
The output is similar to this:
|
The output is similar to this:
|
||||||
|
```shell
|
||||||
Name: example-service
|
Name: example-service
|
||||||
Namespace: default
|
Namespace: default
|
||||||
Labels: run=load-balancer-example
|
Labels: run=load-balancer-example
|
||||||
Annotations: <none>
|
Annotations: <none>
|
||||||
Selector: run=load-balancer-example
|
Selector: run=load-balancer-example
|
||||||
Type: NodePort
|
Type: NodePort
|
||||||
IP: 10.32.0.16
|
IP: 10.32.0.16
|
||||||
Port: <unset> 8080/TCP
|
Port: <unset> 8080/TCP
|
||||||
TargetPort: 8080/TCP
|
TargetPort: 8080/TCP
|
||||||
NodePort: <unset> 31496/TCP
|
NodePort: <unset> 31496/TCP
|
||||||
Endpoints: 10.200.1.4:8080,10.200.2.5:8080
|
Endpoints: 10.200.1.4:8080,10.200.2.5:8080
|
||||||
Session Affinity: None
|
Session Affinity: None
|
||||||
Events: <none>
|
Events: <none>
|
||||||
|
```
|
||||||
Make a note of the NodePort value for the service. For example,
|
Make a note of the NodePort value for the service. For example,
|
||||||
in the preceding output, the NodePort value is 31496.
|
in the preceding output, the NodePort value is 31496.
|
||||||
|
|
||||||
1. List the pods that are running the Hello World application:
|
1. List the pods that are running the Hello World application:
|
||||||
|
```shell
|
||||||
kubectl get pods --selector="run=load-balancer-example" --output=wide
|
kubectl get pods --selector="run=load-balancer-example" --output=wide
|
||||||
|
```
|
||||||
The output is similar to this:
|
The output is similar to this:
|
||||||
|
```shell
|
||||||
NAME READY STATUS ... IP NODE
|
NAME READY STATUS ... IP NODE
|
||||||
hello-world-2895499144-bsbk5 1/1 Running ... 10.200.1.4 worker1
|
hello-world-2895499144-bsbk5 1/1 Running ... 10.200.1.4 worker1
|
||||||
hello-world-2895499144-m1pwt 1/1 Running ... 10.200.2.5 worker2
|
hello-world-2895499144-m1pwt 1/1 Running ... 10.200.2.5 worker2
|
||||||
|
```
|
||||||
1. Get the public IP address of one of your nodes that is running
|
1. Get the public IP address of one of your nodes that is running
|
||||||
a Hello World pod. How you get this address depends on how you set
|
a Hello World pod. How you get this address depends on how you set
|
||||||
up your cluster. For example, if you are using Minikube, you can
|
up your cluster. For example, if you are using Minikube, you can
|
||||||
see the node address by running `kubectl cluster-info`. If you are
|
see the node address by running `kubectl cluster-info`. If you are
|
||||||
using Google Compute Engine instances, you can use the
|
using Google Compute Engine instances, you can use the
|
||||||
`gcloud compute instances list` command to see the public addresses of your
|
`gcloud compute instances list` command to see the public addresses of your
|
||||||
nodes. For more information about this command, see the [GCE documentation](https://cloud.google.com/sdk/gcloud/reference/compute/instances/list).
|
nodes. For more information about this command, see the [GCE documentation](https://cloud.google.com/sdk/gcloud/
|
||||||
|
reference/compute/instances/list).
|
||||||
|
|
||||||
1. On your chosen node, create a firewall rule that allows TCP traffic
|
1. On your chosen node, create a firewall rule that allows TCP traffic
|
||||||
on your node port. For example, if your Service has a NodePort value of
|
on your node port. For example, if your Service has a NodePort value of
|
||||||
31568, create a firewall rule that allows TCP traffic on port 31568. Different
|
31568, create a firewall rule that allows TCP traffic on port 31568. Different
|
||||||
cloud providers offer different ways of configuring firewall rules. See [the
|
cloud providers offer different ways of configuring firewall rules. See [the
|
||||||
GCE documentation on firewall rules](https://cloud.google.com/compute/docs/vpc/firewalls),
|
GCE documentation on firewall rules](https://cloud.google.com/compute/docs/vpc/firewalls),
|
||||||
for example.
|
for example.
|
||||||
|
|
||||||
1. Use the node address and node port to access the Hello World application:
|
1. Use the node address and node port to access the Hello World application:
|
||||||
|
```shell
|
||||||
curl http://<public-node-ip>:<node-port>
|
curl http://<public-node-ip>:<node-port>
|
||||||
|
```
|
||||||
where `<public-node-ip>` is the public IP address of your node,
|
where `<public-node-ip>` is the public IP address of your node,
|
||||||
and `<node-port>` is the NodePort value for your service.
|
and `<node-port>` is the NodePort value for your service. 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!
|
```
|
||||||
|
|
||||||
## Using a service configuration file
|
## Using a service configuration file
|
||||||
|
|
||||||
|
@ -146,6 +150,3 @@ the Hello World application, enter this command:
|
||||||
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/).
|
||||||
{{% /capture %}}
|
{{% /capture %}}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue