Service Discovery for Microservices with Kubernetes

  • Prerequisites
  • Application Architecture
  • Deploy Application
  • Access Application
  • Delete Application

Prerequisites

Application Architecture

  1. webapp: Web application microservice uses greeter and name microservice to generate a greeting for a person.
  2. greeter: A microservice returns a greeting based upon greet name/value keypair in the URL.
  3. name: A microservice that returns a person’s name based upon id name/value keypair in the URL.
  1. NAME_SERVICE_HOST
  2. NAME_SERVICE_PORT
  3. NAME_SERVICE_PATH
  4. GREETER_SERVICE_HOST
  5. GREETER_SERVICE_PORT
  6. GREETER_SERVICE_PATH
spec:
containers:
- name: webapp-pod
image: arungupta/webapp-service:latest
env:
- name: NAME_SERVICE_HOST
value: name-service
- name: NAME_SERVICE_PORT
value: "8080"
- name: NAME_SERVICE_PATH
value: /
- name: GREETER_SERVICE_HOST
value: greeter-service
- name: GREETER_SERVICE_PORT
value: "8080"
- name: GREETER_SERVICE_PATH
value: /
spec:
selector:
app: webapp-pod
ports:
- name: web
port: 80
type: LoadBalancer

Deploy Application

  1. Deploy the application:
$ kubectl create -f templates/app.yml
$ kubectl get svc
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
greeter-service 100.64.44.23 <none> 8080/TCP 13s
kubernetes 100.64.0.1 <none> 443/TCP 23m
name-service 100.66.113.58 <none> 8080/TCP 13s
webapp-service 100.71.126.195 a5427e1288472... 80:31234/TCP 12s
$ kubectl describe svc/webapp-service
Name: webapp-service
Namespace: default
Labels: <none>
Annotations: <none>
Selector: app=webapp-pod
Type: LoadBalancer
IP: 100.71.126.195
LoadBalancer Ingress: a5427e128847211e782280a896fc2bfc-283874069.us-east-1.elb.amazonaws.com
Port: web 80/TCP
NodePort: web 31234/TCP
Endpoints: 100.96.2.12:80
Session Affinity: None
Events:
FirstSeen LastSeen Count From SubObjectPath Type Reason Message
--------- -------- ----- ---- ------------- -------- ------ -------
30s 30s 1 service-controller Normal CreatingLoadBalancer Creating load balancer
29s 29s 1 service-controller Normal CreatedLoadBalancer Created load balancer

Access Application

http://<host>
http://<host>?greet=ho
http://<host>?id=1
http://<host>?greet=ho&id=1
$ kubectl get svc/webapp-service -o jsonpath={.status.loadBalancer.ingress[0].hostname}
a5427e128847211e782280a896fc2bfc-283874069.us-east-1.elb.amazonaws.com

Delete Application

$ kubectl delete -f templates/app.yml

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store