Skip to content

Commit f7b2971

Browse files
Enhancements in clarity to access-application-cluster/connecting-frontend-backend.md (#25927)
* Enhancements in clarity to docs/tasks/access-application-cluster/connecting-frontend-backend.md * Code review comments * Reverting name of service due to backed value in Dockerimage
1 parent ee4af31 commit f7b2971

File tree

9 files changed

+114
-93
lines changed

9 files changed

+114
-93
lines changed

content/en/docs/tasks/access-application-cluster/connecting-frontend-backend.md

Lines changed: 51 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
---
2-
title: Connect a Front End to a Back End Using a Service
2+
title: Connect a Frontend to a Backend Using Services
33
content_type: tutorial
44
weight: 70
55
---
66

77
<!-- overview -->
88

9-
This task shows how to create a frontend and a backend
10-
microservice. The backend microservice is a hello greeter. The
11-
frontend and backend are connected using a Kubernetes
12-
{{< glossary_tooltip term_id="service" >}} object.
9+
This task shows how to create a _frontend_ and a _backend_ microservice. The backend
10+
microservice is a hello greeter. The frontend exposes the backend using nginx and a
11+
Kubernetes {{< glossary_tooltip term_id="service" >}} object.
1312

1413
## {{% heading "objectives" %}}
1514

16-
* Create and run a microservice using a {{< glossary_tooltip term_id="deployment" >}} object.
17-
* Route traffic to the backend using a frontend.
18-
* Use a Service object to connect the frontend application to the
19-
backend application.
15+
* Create and run a sample `hello` backend microservice using a
16+
{{< glossary_tooltip term_id="deployment" >}} object.
17+
* Use a Service object to send traffic to the backend microservice's multiple replicas.
18+
* Create and run a `nginx` frontend microservice, also using a Deployment object.
19+
* Configure the frontend microservice to send traffic to the backend microservice.
20+
* Use a Service object of `type=LoadBalancer` to expose the frontend microservice
21+
outside the cluster.
2022

2123
## {{% heading "prerequisites" %}}
2224

@@ -34,32 +36,32 @@ require a supported environment. If your environment does not support this, you
3436
The backend is a simple hello greeter microservice. Here is the configuration
3537
file for the backend Deployment:
3638

37-
{{< codenew file="service/access/hello.yaml" >}}
39+
{{< codenew file="service/access/backend-deployment.yaml" >}}
3840

3941
Create the backend Deployment:
4042

4143
```shell
42-
kubectl apply -f https://k8s.io/examples/service/access/hello.yaml
44+
kubectl apply -f https://k8s.io/examples/service/access/backend-deployment.yaml
4345
```
4446

4547
View information about the backend Deployment:
4648

4749
```shell
48-
kubectl describe deployment hello
50+
kubectl describe deployment backend
4951
```
5052

5153
The output is similar to this:
5254

5355
```
54-
Name: hello
56+
Name: backend
5557
Namespace: default
5658
CreationTimestamp: Mon, 24 Oct 2016 14:21:02 -0700
5759
Labels: app=hello
5860
tier=backend
5961
track=stable
6062
Annotations: deployment.kubernetes.io/revision=1
6163
Selector: app=hello,tier=backend,track=stable
62-
Replicas: 7 desired | 7 updated | 7 total | 7 available | 0 unavailable
64+
Replicas: 3 desired | 3 updated | 3 total | 3 available | 0 unavailable
6365
StrategyType: RollingUpdate
6466
MinReadySeconds: 0
6567
RollingUpdateStrategy: 1 max unavailable, 1 max surge
@@ -80,57 +82,66 @@ Conditions:
8082
Available True MinimumReplicasAvailable
8183
Progressing True NewReplicaSetAvailable
8284
OldReplicaSets: <none>
83-
NewReplicaSet: hello-3621623197 (7/7 replicas created)
85+
NewReplicaSet: hello-3621623197 (3/3 replicas created)
8486
Events:
8587
...
8688
```
8789

88-
## Creating the backend Service object
90+
## Creating the `hello` Service object
8991

90-
The key to connecting a frontend to a backend is the backend
92+
The key to sending requests from a frontend to a backend is the backend
9193
Service. A Service creates a persistent IP address and DNS name entry
9294
so that the backend microservice can always be reached. A Service uses
9395
{{< glossary_tooltip text="selectors" term_id="selector" >}} to find
9496
the Pods that it routes traffic to.
9597

9698
First, explore the Service configuration file:
9799

98-
{{< codenew file="service/access/hello-service.yaml" >}}
100+
{{< codenew file="service/access/backend-service.yaml" >}}
99101

100-
In the configuration file, you can see that the Service routes traffic to Pods
101-
that have the labels `app: hello` and `tier: backend`.
102+
In the configuration file, you can see that the Service, named `hello` routes
103+
traffic to Pods that have the labels `app: hello` and `tier: backend`.
102104

103-
Create the `hello` Service:
105+
Create the backend Service:
104106

105107
```shell
106-
kubectl apply -f https://k8s.io/examples/service/access/hello-service.yaml
108+
kubectl apply -f https://k8s.io/examples/service/access/backend-service.yaml
107109
```
108110

109-
At this point, you have a backend Deployment running, and you have a
110-
Service that can route traffic to it.
111+
At this point, you have a `backend` Deployment running three replicas of your `hello`
112+
application, and you have a Service that can route traffic to them. However, this
113+
service is neither available nor resolvable outside the cluster.
111114

112115
## Creating the frontend
113116

114-
Now that you have your backend, you can create a frontend that connects to the backend.
115-
The frontend connects to the backend worker Pods by using the DNS name
116-
given to the backend Service. The DNS name is "hello", which is the value
117-
of the `name` field in the preceding Service configuration file.
117+
Now that you have your backend running, you can create a frontend that is accessible
118+
outside the cluster, and connects to the backend by proxying requests to it.
118119

119-
The Pods in the frontend Deployment run an nginx image that is configured
120-
to find the hello backend Service. Here is the nginx configuration file:
120+
The frontend sends requests to the backend worker Pods by using the DNS name
121+
given to the backend Service. The DNS name is `hello`, which is the value
122+
of the `name` field in the `examples/service/access/backend-service.yaml`
123+
configuration file.
121124

122-
{{< codenew file="service/access/frontend.conf" >}}
125+
The Pods in the frontend Deployment run a nginx image that is configured
126+
to proxy requests to the `hello` backend Service. Here is the nginx configuration file:
123127

124-
Similar to the backend, the frontend has a Deployment and a Service. The
125-
configuration for the Service has `type: LoadBalancer`, which means that
126-
the Service uses the default load balancer of your cloud provider.
128+
{{< codenew file="service/access/frontend-nginx.conf" >}}
127129

128-
{{< codenew file="service/access/frontend.yaml" >}}
130+
Similar to the backend, the frontend has a Deployment and a Service. An important
131+
difference to notice between the backend and frontend services, is that the
132+
configuration for the frontend Service has `type: LoadBalancer`, which means that
133+
the Service uses a load balancer provisioned by your cloud provider and will be
134+
accessible from outside the cluster.
135+
136+
{{< codenew file="service/access/frontend-service.yaml" >}}
137+
138+
{{< codenew file="service/access/frontend-deployment.yaml" >}}
129139

130140
Create the frontend Deployment and Service:
131141

132142
```shell
133-
kubectl apply -f https://k8s.io/examples/service/access/frontend.yaml
143+
kubectl apply -f https://k8s.io/examples/service/access/frontend-deployment.yaml
144+
kubectl apply -f https://k8s.io/examples/service/access/frontend-service.yaml
134145
```
135146

136147
The output verifies that both resources were created:
@@ -178,7 +189,7 @@ cluster.
178189

179190
## Send traffic through the frontend
180191

181-
The frontend and backends are now connected. You can hit the endpoint
192+
The frontend and backend are now connected. You can hit the endpoint
182193
by using the curl command on the external IP of your frontend Service.
183194

184195
```shell
@@ -196,17 +207,17 @@ The output shows the message generated by the backend:
196207
To delete the Services, enter this command:
197208

198209
```shell
199-
kubectl delete services frontend hello
210+
kubectl delete services frontend backend
200211
```
201212

202213
To delete the Deployments, the ReplicaSets and the Pods that are running the backend and frontend applications, enter this command:
203214

204215
```shell
205-
kubectl delete deployment frontend hello
216+
kubectl delete deployment frontend backend
206217
```
207218

208219
## {{% heading "whatsnext" %}}
209220

210221
* Learn more about [Services](/docs/concepts/services-networking/service/)
211222
* Learn more about [ConfigMaps](/docs/tasks/configure-pod-container/configure-pod-configmap/)
212-
223+
* Learn more about [DNS for Service and Pods](/docs/concepts/services-networking/dns-pod-service/)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
FROM nginx:1.17.3
22

33
RUN rm /etc/nginx/conf.d/default.conf
4-
COPY frontend.conf /etc/nginx/conf.d
4+
COPY frontend-nginx.conf /etc/nginx/conf.d

content/en/examples/service/access/hello.yaml renamed to content/en/examples/service/access/backend-deployment.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1+
---
12
apiVersion: apps/v1
23
kind: Deployment
34
metadata:
4-
name: hello
5+
name: backend
56
spec:
67
selector:
78
matchLabels:
89
app: hello
910
tier: backend
1011
track: stable
11-
replicas: 7
12+
replicas: 3
1213
template:
1314
metadata:
1415
labels:
@@ -22,3 +23,4 @@ spec:
2223
ports:
2324
- name: http
2425
containerPort: 80
26+
...

content/en/examples/service/access/hello-service.yaml renamed to content/en/examples/service/access/backend-service.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
apiVersion: v1
23
kind: Service
34
metadata:
@@ -10,3 +11,4 @@ spec:
1011
- protocol: TCP
1112
port: 80
1213
targetPort: http
14+
...
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
name: frontend
6+
spec:
7+
selector:
8+
matchLabels:
9+
app: hello
10+
tier: frontend
11+
track: stable
12+
replicas: 1
13+
template:
14+
metadata:
15+
labels:
16+
app: hello
17+
tier: frontend
18+
track: stable
19+
spec:
20+
containers:
21+
- name: nginx
22+
image: "gcr.io/google-samples/hello-frontend:1.0"
23+
lifecycle:
24+
preStop:
25+
exec:
26+
command: ["/usr/sbin/nginx","-s","quit"]
27+
...
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# The identifier Backend is internal to nginx, and used to name this specific upstream
2+
upstream Backend {
3+
# hello is the internal DNS name used by the backend Service inside Kubernetes
4+
server hello;
5+
}
6+
7+
server {
8+
listen 80;
9+
10+
location / {
11+
# The following statement will proxy traffic to the upstream named Backend
12+
proxy_pass http://Backend;
13+
}
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
apiVersion: v1
3+
kind: Service
4+
metadata:
5+
name: frontend
6+
spec:
7+
selector:
8+
app: hello
9+
tier: frontend
10+
ports:
11+
- protocol: "TCP"
12+
port: 80
13+
targetPort: 80
14+
type: LoadBalancer
15+
...

content/en/examples/service/access/frontend.conf

Lines changed: 0 additions & 11 deletions
This file was deleted.

content/en/examples/service/access/frontend.yaml

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)