-
Notifications
You must be signed in to change notification settings - Fork 5
Kubernetes Services
There are multiple kinds of services. Services are there in order to expose access (internal or external) to Pods. Let's assume that we labeled some pods with 'couchbase-cluster', then the following descriptor would expose the Couchbase Admin port internally:
apiVersion: v1
kind: Service
metadata:
name: couchbase-cluster-int
labels:
name: couchbase-cluster
spec:
ports:
- port: 8091
selector:
name: couchbase-cluster
In order to register our service, the following command can be issued:
kubectl.sh create -f couchbase-service-internal.yaml
In order to list our services, we can then use:
david@steambox:~/Git/dmaier-couchbase/cb-openshift3/examples/k8s$ kubectl.sh get services -l name=couchbase-cluster
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
couchbase-cluster-int 10.247.202.160 <none> 8091/TCP 5m
The discovery works via environment variables:
david@steambox:~/Git/dmaier-couchbase/cb-openshift3/examples/k8s$ kubectl.sh exec couchbase-cluster-hhb2z -- env | grep COUCHBASE_CLUSTER_INT
COUCHBASE_CLUSTER_INT_SERVICE_HOST=10.247.202.160
COUCHBASE_CLUSTER_INT_PORT_8091_TCP_ADDR=10.247.202.160
COUCHBASE_CLUSTER_INT_PORT_8091_TCP_PROTO=tcp
COUCHBASE_CLUSTER_INT_PORT_8091_TCP_PORT=8091
COUCHBASE_CLUSTER_INT_PORT_8091_TCP=tcp://10.247.202.160:8091
COUCHBASE_CLUSTER_INT_SERVICE_PORT=8091
COUCHBASE_CLUSTER_INT_PORT=tcp://10.247.202.160:8091
The idea of services is that (as far as I understand) they are exposed via a Kube-Proxy (running on the minion node). This is usually a very good thing because it decouples the access to a specific endpoint from the actual instances those are providing it. Means that this proxy just forwards the access to several endpoints. Our 3 node replica set then causes 3 endpoints those are only accessible via Kube-Proxy:
Name: couchbase-cluster-int
Namespace: default
Labels: name=couchbase-cluster
Selector: name=couchbase-cluster
Type: ClusterIP
IP: 10.247.202.160
Port: <unset> 8091/TCP
Endpoints: 10.246.34.5:8091,10.246.34.6:8091,10.246.34.7:8091
Session Affinity: None