@@ -10,26 +10,15 @@ This page shows how to create a Kubernetes Service object that external
10
10
clients can use to access an application running in a cluster. The Service
11
11
provides load balancing for an application that has two running instances.
12
12
13
-
14
-
15
-
16
13
## {{% heading "prerequisites" %}}
17
14
18
-
19
15
{{< include "task-tutorial-prereqs.md" >}}
20
16
21
-
22
-
23
-
24
17
## {{% heading "objectives" %}}
25
18
26
-
27
- * Run two instances of a Hello World application.
28
- * Create a Service object that exposes a node port.
29
- * Use the Service object to access the running application.
30
-
31
-
32
-
19
+ - Run two instances of a Hello World application.
20
+ - Create a Service object that exposes a node port.
21
+ - Use the Service object to access the running application.
33
22
34
23
<!-- lessoncontent -->
35
24
@@ -41,9 +30,11 @@ Here is the configuration file for the application Deployment:
41
30
42
31
1 . Run a Hello World application in your cluster:
43
32
Create the application Deployment using the file above:
33
+
44
34
``` shell
45
35
kubectl apply -f https://k8s.io/examples/service/access/hello-application.yaml
46
36
```
37
+
47
38
The preceding command creates a
48
39
{{< glossary_tooltip text="Deployment" term_id="deployment" >}}
49
40
and an associated
@@ -52,30 +43,35 @@ Here is the configuration file for the application Deployment:
52
43
{{< glossary_tooltip text="Pods" term_id="pod" >}}
53
44
each of which runs the Hello World application.
54
45
55
-
56
46
1 . Display information about the Deployment:
47
+
57
48
``` shell
58
49
kubectl get deployments hello-world
59
50
kubectl describe deployments hello-world
60
51
```
61
52
62
53
1 . Display information about your ReplicaSet objects:
54
+
63
55
``` shell
64
56
kubectl get replicasets
65
57
kubectl describe replicasets
66
58
```
67
59
68
60
1 . Create a Service object that exposes the deployment:
61
+
69
62
``` shell
70
63
kubectl expose deployment hello-world --type=NodePort --name=example-service
71
64
```
72
65
73
66
1 . Display information about the Service:
67
+
74
68
``` shell
75
69
kubectl describe services example-service
76
70
```
71
+
77
72
The output is similar to this:
78
- ``` shell
73
+
74
+ ``` none
79
75
Name: example-service
80
76
Namespace: default
81
77
Labels: run=load-balancer-example
@@ -90,19 +86,24 @@ Here is the configuration file for the application Deployment:
90
86
Session Affinity: None
91
87
Events: <none>
92
88
```
89
+
93
90
Make a note of the NodePort value for the service. For example,
94
91
in the preceding output, the NodePort value is 31496.
95
92
96
93
1 . List the pods that are running the Hello World application:
94
+
97
95
``` shell
98
96
kubectl get pods --selector=" run=load-balancer-example" --output=wide
99
97
```
98
+
100
99
The output is similar to this:
101
- ``` shell
100
+
101
+ ``` none
102
102
NAME READY STATUS ... IP NODE
103
103
hello-world-2895499144-bsbk5 1/1 Running ... 10.200.1.4 worker1
104
104
hello-world-2895499144-m1pwt 1/1 Running ... 10.200.2.5 worker2
105
105
```
106
+
106
107
1 . Get the public IP address of one of your nodes that is running
107
108
a Hello World pod. How you get this address depends on how you set
108
109
up your cluster. For example, if you are using Minikube, you can
@@ -117,13 +118,16 @@ Here is the configuration file for the application Deployment:
117
118
cloud providers offer different ways of configuring firewall rules.
118
119
119
120
1 . Use the node address and node port to access the Hello World application:
121
+
120
122
``` shell
121
123
curl http://< public-node-ip> :< node-port>
122
124
```
125
+
123
126
where ` <public-node-ip> ` is the public IP address of your node,
124
127
and ` <node-port> ` is the NodePort value for your service. The
125
128
response to a successful request is a hello message:
126
- ``` shell
129
+
130
+ ``` none
127
131
Hello Kubernetes!
128
132
```
129
133
@@ -133,12 +137,8 @@ As an alternative to using `kubectl expose`, you can use a
133
137
[ service configuration file] ( /docs/concepts/services-networking/service/ )
134
138
to create a Service.
135
139
136
-
137
-
138
-
139
140
## {{% heading "cleanup" %}}
140
141
141
-
142
142
To delete the Service, enter this command:
143
143
144
144
kubectl delete services example-service
@@ -148,9 +148,6 @@ the Hello World application, enter this command:
148
148
149
149
kubectl delete deployment hello-world
150
150
151
-
152
-
153
-
154
151
## {{% heading "whatsnext" %}}
155
152
156
153
Follow the
0 commit comments