Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Service discovery in kubernetes with fabric8
1. BASEL BERN BRUGG DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. GENF
HAMBURG KOPENHAGEN LAUSANNE MÜNCHEN STUTTGART WIEN ZÜRICH
Service discovery in Kubernetes with
Fabric8Andy Moncsek
Senior Consultant
Andy.Moncsek@trivadis.com
Twitter: @AndyAHCP
2. Agenda
2 27.10.2017
1. Why service discovery?
2. Some Kubernetes basics
3. Service discovery in Kubernetes
4. Fabric8 & Service discovery
Service discovery in Kubernetes with Fabric8
4. Why Service discovery ?
Service discovery in Kubernetes with Fabric84 27.10.2017
Dynamically
assigned
172.178.178.1:56477
172.178.178.2:66467
172.178.178.3:76767
Client /
API
Gatewa
y
?
Dynamically
changing
Loadbalancing?
6. Server-side discovery
Service discovery in Kubernetes with Fabric86 27.10.2017
1.
register
2. request
3.
query
4.
Loadbalance
Client does
not know a
specific
service
instance
8. Some Kubernetes basics: What it is....
Kubernetes is platform designed to automate deploying,
scaling, and operating application containers.
Deploy your applications quickly and predictably.
Scale your applications on the fly.
Roll out new features seamlessly.
Service discovery in Kubernetes with Fabric88 27.10.2017
10. Kubernetes Pods
Group of containers
Shares network/namespace/ IP
Shares environmental variables
Shared volumes
10 27.10.2017 Service discovery in Kubernetes with Fabric8
12. Kubernetes Services
12 27.10.2017 Service discovery in Kubernetes with Fabric8
Pod discovery
IP per service
1-N port numbers
Route to pods
Load balancer
14. Kubernetes Services (3)
14 27.10.2017 Service discovery in Kubernetes with Fabric8
External IP depends on:
Service type = LB
Infrastructure
15. Kubernetes Services (4)
15 27.10.2017 Service discovery in Kubernetes with Fabric8
Cluster IP:
Internal IP address
Accessible by any
component in
namespace
16. Kubernetes Services (5)
16 27.10.2017 Service discovery in Kubernetes with Fabric8
NodePort:
Unique per service
$NODE_IP:$NODEPORT
ClusterIP references a
NodePort on a specific
Node
17. Kubernetes Services (6)
17 27.10.2017 Service discovery in Kubernetes with Fabric8
Endpoints:
1:1 Endpoint – Pod
Represents the IP
address of a Pod
Can be queried by API
18. Service discovery in Kubernetes
Service discovery in Kubernetes with Fabric818 27.10.2017
19. Service discovery in Kubernetes
How you can find your services in Kubernetes?
Install Consul, Zookeeper, ... Out of scope ;-)
Discovery using Environment variables
Discovery using DNS
Discovery using Kubernetes master (with Fabric8 API)
Service discovery in Kubernetes with Fabric819 27.10.2017
20. Service discovery in Kubernetes
Discovery using Environment variables
When a Pod starts, a set of env variables for each active service
added
{SVCNAME}_SERVICE_HOST & {SVCNAME}_SERVICE_PORT
In case of many port definitions the port name is added:
{SVCNAME}_SERVICE_PORT_{PORTNAME}
Drawback: the Service must already exist!
Service discovery in Kubernetes with Fabric820 27.10.2017
21. Service discovery in Kubernetes
Discovery using DNS
The DNS Server watches the Kubernetes API for new Services
Creates a set of DNS records for each
E.g. Service: “myservice”, Namespace: “default” myservice.default
You can access the service using: http://myservice/…...
Drawback:
DNS must be enabled
No protocol- & port-information
Service discovery in Kubernetes with Fabric821 27.10.2017
22. Fabric8 & service discovery
Service discovery in Kubernetes with Fabric822 27.10.2017
23. Fabric8 & service discovery
What is Fabric8?
Fabric8 is an integrated open source DevOps and Integration
Platform which works out of the box on any Kubernetes or
OpenShift environment and provides Continuous Delivery,
Management, ChatOps and a Chaos Monkey.
Service discovery in Kubernetes with Fabric823 27.10.2017
24. Fabric8 & service discovery
The Fabric8 kubernetes-client (http://goo.gl/17Hbp1)
provides a Java API for working with the Kubernetes and
OpenShift REST API
The kubernetes-client API is used by many projects:
Several discovery plugins (e.g. Hazelcast)
fabric8-spring-boot (https://goo.gl/JgN721)
K8sdiscovery (https://goo.gl/Hok1gT)
Service discovery in Kubernetes with Fabric824 27.10.2017
25. Fabric8 & service discovery
Why & When do you want to use fabric8 kubernetes-client?
Discover Endpoints (Pods) for Client-side LB or monitoring
Simple discovery of different ports / protocols
Discovery using labels!
Service discovery in Kubernetes with Fabric825 27.10.2017
26. Fabric8 & service discovery - Example
Service discovery in Kubernetes with Fabric826 27.10.2017
client.
endpoints().
inNamespace(„hazelcast
“).
withLabel(„cluster1“).list
()
client.
endpoints().
inNamespace(„hazelcast
“).
withLabel(„cluster2“).list
()
spec:
replicas: 3
template:
metadata:
labels:
cluster1
33. Discover external Services
Solution:
Services without selectors
Service with ExternalName
Service discovery in Kubernetes with Fabric833 27.10.2017
34. Services without selectors
Service discovery in Kubernetes with Fabric834 27.10.2017
kind: Service
apiVersion: v1
metadata:
name: my-service
spec:
selector:
app: MyApp
ports:
- protocol: TCP
port: 80
targetPort: 9376
kind: Endpoints
apiVersion: v1
metadata:
name: my-service
subsets:
- addresses:
- ip: 1.2.3.4
ports:
- port: 9376
Manually deploy
35. Service with ExternalName
Service discovery in Kubernetes with Fabric835 27.10.2017
kind: Service
apiVersion: v1
metadata:
name: my-service
namespace: prod
spec:
type: ExternalName
externalName: my.database.com
my-service.prod.svc.CLUSTER CNAME =
my.database.com
36. Summary
Use discovery by Service name (DNS) in simple cases
Use env variables for Port discovery
Use Fabric8 Kubernetes-Client discovery when:
Endpoint discovery needed (Client-Side discovery)
Labels are working better for you
Dealing with different ports
Metadata is needed (monitoring)
Service discovery in Kubernetes with Fabric836 27.10.2017
37. Thank you
Andy Moncsek
Senior Consultant
Andy.Moncsek@trivadis.com
Twitter: @AndyAHCP
27.10.201737 Service discovery in Kubernetes with Fabric8