0% found this document useful (0 votes)
82 views

Kubernetes Deploy Frontend and Backend

This document describes how to connect a frontend to a backend using Kubernetes services. It involves creating a backend deployment and service, then a frontend deployment that proxies requests to the backend service. The frontend service is exposed outside the cluster using type: LoadBalancer so it is accessible externally.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views

Kubernetes Deploy Frontend and Backend

This document describes how to connect a frontend to a backend using Kubernetes services. It involves creating a backend deployment and service, then a frontend deployment that proxies requests to the backend service. The frontend service is exposed outside the cluster using type: LoadBalancer so it is accessible externally.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

kubernetes deploy frontend and backend

Connect a Frontend to a Backend


Using Services
https://kubernetes.io/docs/tasks/access-application-cluster/connecting-frontend-backend/

Create the backend Deployment:


kubectl apply -f
https://k8s.io/examples/service/access/backend-deployment.yaml

View information about the backend Deployment:

kubectl describe deployment backend

Creating the  hello Service object


Create the backend Service:
kubectl apply -f
https://k8s.io/examples/service/access/backend-service.yaml

At this point, you have a backend Deployment running three replicas of your hello
application, and you have a Service that can route traffic to them. However, this service is
neither available nor resolvable outside the cluster

Creating the frontend

Now that you have your backend running, you can create a frontend that is accessible
outside the cluster, and connects to the backend by proxying requests to it.

The frontend sends requests to the backend worker Pods by using the DNS name given to
the backend Service. The DNS name is hello, which is the value of the name field in the
examples/service/access/backend-service.yaml configuration file.

The Pods in the frontend Deployment run a nginx image that is configured to proxy requests
to the hello backend Service. Here is the nginx configuration file:
# The identifier Backend is internal to nginx, and used to
name this specific upstream
upstream Backend {
# hello is the internal DNS name used by the backend
Service inside Kubernetes
server hello;
}

server {
listen 80;

location / {
# The following statement will proxy traffic to the
upstream named Backend
proxy_pass http://Backend;
}

},

Similar to the backend, the frontend has a Deployment and a Service. An important
difference to notice between the backend and frontend services, is that the configuration for
the frontend Service has type: LoadBalancer, which means that the Service uses a load
balancer provisioned by your cloud provider and will be accessible from outside the cluster.

Create the frontend Deployment and Service:

kubectl apply -f
https://k8s.io/examples/service/access/frontend-
deployment.yaml
kubectl apply -f
https://k8s.io/examples/service/access/frontend-service.yaml

The output verifies that both resources were created:

deployment.apps/frontend created
service/frontend created
Interact with the frontend Service

Once you've created a Service of type LoadBalancer, you can use this command to find the
external IP:

kubectl get service frontend --watch

This displays the configuration for the frontend Service and watches for changes. Initially,
the external IP is listed as <pending>:

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE

frontend LoadBalancer 10.51.252.116 <pending> 80/TCP 10s

As soon as an external IP is provisioned, however, the configuration updates to include the


new IP under the EXTERNAL-IP heading:

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE

frontend LoadBalancer 10.51.252.116 XXX.XXX.XXX.XXX 80/TCP 1m

That IP can now be used to interact with the frontend service from outside the cluster.

Send traffic through the frontend

The frontend and backend are now connected. You can hit the endpoint by using the curl
command on the external IP of your frontend Service.

curl http://${EXTERNAL_IP} # replace this with the EXTERNAL-IP you saw earlier

The output shows the message generated by the backend:

{"message":"Hello"}

You might also like