@@ -114,6 +114,20 @@ access from a Spring Boot application running as a pod.
114114
115115This is something that you get for free by adding the following dependency inside your project:
116116
117+ ====
118+ HTTP Based `DiscoveryClient`
119+ [source,xml]
120+ ----
121+ <dependency>
122+ <groupId>org.springframework.cloud</groupId>
123+ <artifactId>spring-cloud-starter-kubernetes-discoveryclient</artifactId>
124+ </dependency>
125+ ----
126+ ====
127+
128+ NOTE: `spring-cloud-starter-kubernetes-discoveryclient` is designed to be used with the
129+ <<spring-cloud-kubernetes-discoveryserver, Spring Cloud Kubernetes DiscoveryServer>>.
130+
117131====
118132Fabric8 Kubernetes Client
119133[source,xml]
@@ -1514,6 +1528,219 @@ items:
15141528----
15151529====
15161530
1531+ [#spring-cloud-kubernetes-discoveryserver]
1532+ ## Spring Cloud Kubernetes Discovery Server
1533+
1534+ The Spring Cloud Kubernetes Discovery Server provides HTTP endpoints apps can use to gather information
1535+ about services available within a Kubernetes cluster. The Spring Cloud Kubernetes Discovery Server
1536+ can be used by apps using the `spring-cloud-starter-kubernetes-discoveryclient` to provide data to
1537+ the `DiscoveryClient` implementation provided by that starter.
1538+
1539+ ### Permissions
1540+ The Spring Cloud Discovery server uses
1541+ the Kubernetes API server to get data about Service and Endpoint resrouces so it needs list, watch, and
1542+ get permissions to use those endpoints. See the below sample Kubernetes deployment YAML for an
1543+ examlpe of how to configure the Service Account on Kubernetes.
1544+
1545+
1546+ ### Endpoints
1547+ There are three endpoints exposed by the server.
1548+
1549+ #### `/apps`
1550+
1551+ A `GET` request sent to `/apps` will return a JSON array of available services. Each item contains
1552+ the name of the Kubernetes service and service instance information. Below is a sample response.
1553+
1554+ ====
1555+ [source,json]
1556+ ----
1557+ [
1558+ {
1559+ "name":"spring-cloud-kubernetes-discoveryserver",
1560+ "serviceInstances":[
1561+ {
1562+ "instanceId":"836a2f25-daee-4af2-a1be-aab9ce2b938f",
1563+ "serviceId":"spring-cloud-kubernetes-discoveryserver",
1564+ "host":"10.244.1.6",
1565+ "port":8761,
1566+ "uri":"http://10.244.1.6:8761",
1567+ "secure":false,
1568+ "metadata":{
1569+ "app":"spring-cloud-kubernetes-discoveryserver",
1570+ "kubectl.kubernetes.io/last-applied-configuration":"{\"apiVersion\":\"v1\",\"kind\":\"Service\",\"metadata\":{\"annotations\":{},\"labels\":{\"app\":\"spring-cloud-kubernetes-discoveryserver\"},\"name\":\"spring-cloud-kubernetes-discoveryserver\",\"namespace\":\"default\"},\"spec\":{\"ports\":[{\"name\":\"http\",\"port\":80,\"targetPort\":8761}],\"selector\":{\"app\":\"spring-cloud-kubernetes-discoveryserver\"},\"type\":\"ClusterIP\"}}\n",
1571+ "http":"8761"
1572+ },
1573+ "namespace":"default",
1574+ "scheme":"http"
1575+ }
1576+ ]
1577+ },
1578+ {
1579+ "name":"kubernetes",
1580+ "serviceInstances":[
1581+ {
1582+ "instanceId":"1234",
1583+ "serviceId":"kubernetes",
1584+ "host":"172.18.0.3",
1585+ "port":6443,
1586+ "uri":"http://172.18.0.3:6443",
1587+ "secure":false,
1588+ "metadata":{
1589+ "provider":"kubernetes",
1590+ "component":"apiserver",
1591+ "https":"6443"
1592+ },
1593+ "namespace":"default",
1594+ "scheme":"http"
1595+ }
1596+ ]
1597+ }
1598+ ]
1599+ ----
1600+ ====
1601+
1602+ #### `/app/{name}`
1603+
1604+ A `GET` request to `/app/{name}` can be used to get instance data for all instances of a given
1605+ service. Below is a sample response when a `GET` request is made to `/app/kubernetes`.
1606+
1607+ ====
1608+ [source,json]
1609+ ----
1610+ [
1611+ {
1612+ "instanceId":"1234",
1613+ "serviceId":"kubernetes",
1614+ "host":"172.18.0.3",
1615+ "port":6443,
1616+ "uri":"http://172.18.0.3:6443",
1617+ "secure":false,
1618+ "metadata":{
1619+ "provider":"kubernetes",
1620+ "component":"apiserver",
1621+ "https":"6443"
1622+ },
1623+ "namespace":"default",
1624+ "scheme":"http"
1625+ }
1626+ ]
1627+ ----
1628+ ====
1629+
1630+ #### `/app/{name}/{instanceid}`
1631+
1632+ A `GET` request made to `/app/{name}/{instanceid}` will return the instance data for a specific
1633+ instance of a given service. Below is a sample response when a `GET` request is made to `/app/kubernetes/1234`.
1634+
1635+ ====
1636+ [source,json]
1637+ ----
1638+ {
1639+ "instanceId":"1234",
1640+ "serviceId":"kubernetes",
1641+ "host":"172.18.0.3",
1642+ "port":6443,
1643+ "uri":"http://172.18.0.3:6443",
1644+ "secure":false,
1645+ "metadata":{
1646+ "provider":"kubernetes",
1647+ "component":"apiserver",
1648+ "https":"6443"
1649+ },
1650+ "namespace":"default",
1651+ "scheme":"http"
1652+ }
1653+ ----
1654+ ====
1655+
1656+ ### Deployment YAML
1657+
1658+ An image of the Spring Cloud Discovery Server is hosted on Docker Hub.
1659+
1660+ Below is a sample deployment YAML you can use to deploy the Kubernetes Configuration Watcher to Kubernetes.
1661+
1662+ ====
1663+ [source,yaml]
1664+ ----
1665+ ---
1666+ apiVersion: v1
1667+ kind: List
1668+ items:
1669+ - apiVersion: v1
1670+ kind: Service
1671+ metadata:
1672+ labels:
1673+ app: spring-cloud-kubernetes-discoveryserver
1674+ name: spring-cloud-kubernetes-discoveryserver
1675+ spec:
1676+ ports:
1677+ - name: http
1678+ port: 80
1679+ targetPort: 8761
1680+ selector:
1681+ app: spring-cloud-kubernetes-discoveryserver
1682+ type: ClusterIP
1683+ - apiVersion: v1
1684+ kind: ServiceAccount
1685+ metadata:
1686+ labels:
1687+ app: spring-cloud-kubernetes-discoveryserver
1688+ name: spring-cloud-kubernetes-discoveryserver
1689+ - apiVersion: rbac.authorization.k8s.io/v1
1690+ kind: RoleBinding
1691+ metadata:
1692+ labels:
1693+ app: spring-cloud-kubernetes-discoveryserver
1694+ name: spring-cloud-kubernetes-discoveryserver:view
1695+ roleRef:
1696+ kind: Role
1697+ apiGroup: rbac.authorization.k8s.io
1698+ name: namespace-reader
1699+ subjects:
1700+ - kind: ServiceAccount
1701+ name: spring-cloud-kubernetes-discoveryserver
1702+ - apiVersion: rbac.authorization.k8s.io/v1
1703+ kind: Role
1704+ metadata:
1705+ namespace: default
1706+ name: namespace-reader
1707+ rules:
1708+ - apiGroups: ["", "extensions", "apps"]
1709+ resources: ["services", "endpoints"]
1710+ verbs: ["get", "list", "watch"]
1711+ - apiVersion: apps/v1
1712+ kind: Deployment
1713+ metadata:
1714+ name: spring-cloud-kubernetes-discoveryserver-deployment
1715+ spec:
1716+ selector:
1717+ matchLabels:
1718+ app: spring-cloud-kubernetes-discoveryserver
1719+ template:
1720+ metadata:
1721+ labels:
1722+ app: spring-cloud-kubernetes-discoveryserver
1723+ spec:
1724+ serviceAccount: spring-cloud-kubernetes-discoveryserver
1725+ containers:
1726+ - name: spring-cloud-kubernetes-discoveryserver
1727+ image: springcloud/spring-cloud-kubernetes-discoveryserver:2.1.0-SNAPSHOT
1728+ imagePullPolicy: IfNotPresent
1729+ readinessProbe:
1730+ httpGet:
1731+ port: 8761
1732+ path: /actuator/health/readiness
1733+ livenessProbe:
1734+ httpGet:
1735+ port: 8761
1736+ path: /actuator/health/liveness
1737+ ports:
1738+ - containerPort: 8761
1739+
1740+
1741+ ----
1742+ ====
1743+
15171744== Examples
15181745
15191746Spring Cloud Kubernetes tries to make it transparent for your applications to consume Kubernetes Native Services by
0 commit comments