@@ -9,12 +9,8 @@ weight: 10
9
9
This page shows how to create a Kubernetes Service object that exposes an
10
10
external IP address.
11
11
12
-
13
-
14
-
15
12
## {{% heading "prerequisites" %}}
16
13
17
-
18
14
* Install [ kubectl] ( /docs/tasks/tools/install-kubectl/ ) .
19
15
20
16
* Use a cloud provider like Google Kubernetes Engine or Amazon Web Services to
@@ -25,19 +21,12 @@ external IP address.
25
21
* Configure ` kubectl ` to communicate with your Kubernetes API server. For
26
22
instructions, see the documentation for your cloud provider.
27
23
28
-
29
-
30
-
31
24
## {{% heading "objectives" %}}
32
25
33
-
34
26
* Run five instances of a Hello World application.
35
27
* Create a Service object that exposes an external IP address.
36
28
* Use the Service object to access the running application.
37
29
38
-
39
-
40
-
41
30
<!-- lessoncontent -->
42
31
43
32
## Creating a service for an application running in five pods
@@ -50,37 +39,46 @@ external IP address.
50
39
kubectl apply -f https://k8s.io/examples/service/load-balancer-example.yaml
51
40
```
52
41
53
-
54
42
The preceding command creates a
55
- {{< glossary_tooltip text="Deployment" term_id="deployment" >}}
56
- and an associated
57
- {{< glossary_tooltip term_id="replica-set" text="ReplicaSet" >}}.
58
- The ReplicaSet has five
59
- {{< glossary_tooltip text="Pods" term_id="pod" >}}
60
- each of which runs the Hello World application.
43
+ {{< glossary_tooltip text="Deployment" term_id="deployment" >}}
44
+ and an associated
45
+ {{< glossary_tooltip term_id="replica-set" text="ReplicaSet" >}}.
46
+ The ReplicaSet has five
47
+ {{< glossary_tooltip text="Pods" term_id="pod" >}}
48
+ each of which runs the Hello World application.
61
49
62
50
1 . Display information about the Deployment:
63
51
64
- kubectl get deployments hello-world
65
- kubectl describe deployments hello-world
52
+ ``` shell
53
+ kubectl get deployments hello-world
54
+ kubectl describe deployments hello-world
55
+ ```
66
56
67
57
1. Display information about your ReplicaSet objects:
68
58
69
- kubectl get replicasets
70
- kubectl describe replicasets
59
+ ` ` ` shell
60
+ kubectl get replicasets
61
+ kubectl describe replicasets
62
+ ` ` `
71
63
72
64
1. Create a Service object that exposes the deployment:
73
65
74
- kubectl expose deployment hello-world --type=LoadBalancer --name=my-service
66
+ ` ` ` shell
67
+ kubectl expose deployment hello-world --type=LoadBalancer --name=my-service
68
+ ` ` `
75
69
76
70
1. Display information about the Service:
77
71
78
- kubectl get services my-service
72
+ ` ` ` shell
73
+ kubectl get services my-service
74
+ ` ` `
79
75
80
76
The output is similar to this:
81
77
82
- NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
83
- my-service LoadBalancer 10.3.245.137 104.198.205.71 8080/TCP 54s
78
+ ```
79
+ NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
80
+ my-service LoadBalancer 10.3.245.137 104.198.205.71 8080/TCP 54s
81
+ ```
84
82
85
83
{{< note > }}
86
84
@@ -96,23 +94,27 @@ The preceding command creates a
96
94
97
95
1. Display detailed information about the Service:
98
96
99
- kubectl describe services my-service
97
+ ` ` ` shell
98
+ kubectl describe services my-service
99
+ ` ` `
100
100
101
101
The output is similar to this:
102
102
103
- Name: my-service
104
- Namespace: default
105
- Labels: app.kubernetes.io/name=load-balancer-example
106
- Annotations: <none>
107
- Selector: app.kubernetes.io/name=load-balancer-example
108
- Type: LoadBalancer
109
- IP: 10.3.245.137
110
- LoadBalancer Ingress: 104.198.205.71
111
- Port: <unset> 8080/TCP
112
- NodePort: <unset> 32377/TCP
113
- Endpoints: 10.0.0.6:8080,10.0.1.6:8080,10.0.1.7:8080 + 2 more...
114
- Session Affinity: None
115
- Events: <none>
103
+ ` ` `
104
+ Name: my-service
105
+ Namespace: default
106
+ Labels: app.kubernetes.io/name=load-balancer-example
107
+ Annotations: < none>
108
+ Selector: app.kubernetes.io/name=load-balancer-example
109
+ Type: LoadBalancer
110
+ IP: 10.3.245.137
111
+ LoadBalancer Ingress: 104.198.205.71
112
+ Port: < unset> 8080/TCP
113
+ NodePort: < unset> 32377/TCP
114
+ Endpoints: 10.0.0.6:8080,10.0.1.6:8080,10.0.1.7:8080 + 2 more...
115
+ Session Affinity: None
116
+ Events: < none>
117
+ ` ` `
116
118
117
119
Make a note of the external IP address (` LoadBalancer Ingress` ) exposed by
118
120
your service. In this example, the external IP address is 104.198.205.71.
@@ -124,21 +126,27 @@ The preceding command creates a
124
126
addresses of the pods that are running the Hello World application. To
125
127
verify these are pod addresses, enter this command:
126
128
127
- kubectl get pods --output=wide
129
+ ` ` ` shell
130
+ kubectl get pods --output=wide
131
+ ` ` `
128
132
129
133
The output is similar to this:
130
134
131
- NAME ... IP NODE
132
- hello-world-2895499144-1jaz9 ... 10.0.1.6 gke-cluster-1-default-pool-e0b8d269-1afc
133
- hello-world-2895499144-2e5uh ... 10.0.1.8 gke-cluster-1-default-pool-e0b8d269-1afc
134
- hello-world-2895499144-9m4h1 ... 10.0.0.6 gke-cluster-1-default-pool-e0b8d269-5v7a
135
- hello-world-2895499144-o4z13 ... 10.0.1.7 gke-cluster-1-default-pool-e0b8d269-1afc
136
- hello-world-2895499144-segjf ... 10.0.2.5 gke-cluster-1-default-pool-e0b8d269-cpuc
135
+ ` ` `
136
+ NAME ... IP NODE
137
+ hello-world-2895499144-1jaz9 ... 10.0.1.6 gke-cluster-1-default-pool-e0b8d269-1afc
138
+ hello-world-2895499144-2e5uh ... 10.0.1.8 gke-cluster-1-default-pool-e0b8d269-1afc
139
+ hello-world-2895499144-9m4h1 ... 10.0.0.6 gke-cluster-1-default-pool-e0b8d269-5v7a
140
+ hello-world-2895499144-o4z13 ... 10.0.1.7 gke-cluster-1-default-pool-e0b8d269-1afc
141
+ hello-world-2895499144-segjf ... 10.0.2.5 gke-cluster-1-default-pool-e0b8d269-cpuc
142
+ ` ` `
137
143
138
144
1. Use the external IP address (` LoadBalancer Ingress` ) to access the Hello
139
145
World application:
140
146
141
- curl http://<external-ip>:<port>
147
+ ` ` ` shell
148
+ curl http://< external-ip> :< port>
149
+ ` ` `
142
150
143
151
where ` < external-ip> ` is the external IP address (` LoadBalancer Ingress` )
144
152
of your Service, and ` < port> ` is the value of ` Port` in your Service
@@ -148,29 +156,27 @@ The preceding command creates a
148
156
149
157
The response to a successful request is a hello message:
150
158
151
- Hello Kubernetes!
152
-
153
-
154
-
159
+ ` ` ` shell
160
+ Hello Kubernetes!
161
+ ` ` `
155
162
156
163
# # {{% heading "cleanup" %}}
157
164
158
-
159
165
To delete the Service, enter this command:
160
166
161
- kubectl delete services my-service
167
+ ` ` ` shell
168
+ kubectl delete services my-service
169
+ ` ` `
162
170
163
171
To delete the Deployment, the ReplicaSet, and the Pods that are running
164
172
the Hello World application, enter this command:
165
173
166
- kubectl delete deployment hello-world
167
-
168
-
169
-
174
+ ` ` ` shell
175
+ kubectl delete deployment hello-world
176
+ ` ` `
170
177
171
178
# # {{% heading "whatsnext" %}}
172
179
173
-
174
180
Learn more about
175
181
[connecting applications with services](/docs/concepts/services-networking/connect-applications-service/).
176
182
0 commit comments