Skip to content

Files

Latest commit

 

History

History
150 lines (148 loc) · 3.64 KB

File metadata and controls

150 lines (148 loc) · 3.64 KB

Using external services inside Kubernetes

 

Components

Networks

  • Host network: 192.168.0.0/24
  • Service network: 10.0.0.0/16
  • Pod network: 172.16.0.0/16

Hosts

  • master01: 192.168.0.1
  • master02: 192.168.0.2
  • master03: 192.168.0.3
  • pgsql-master: 192.168.0.10
  • pgsql-slave: 192.168.0.11

Services

  • kubernetes: 10.0.0.1
  • dns: 10.0.0.254

“Normal” flow

./normal_flow.png

External services

Configuration way

export DATABASE_URL='postgresql://application@192.168.0.10:5432/production_db'

./configuration_way.png

WRONG

Database failure

export DATABASE_URL='postgresql://application@192.168.0.11:5432/production_db'
  • You should resetup ALL related deployments and restart ALL theirs pods for hosted service address reconfiguration

DNS way

postgres IN A 192.168.0.10
export DATABASE_URL="postgresql://application@postgres.somezone.tld:5432/production_db"

./dns_way.png

WRONG!

Database failure

  • update DNS record
  • Remember about DNS cache
  • Actually it is easier to kill all related pods

External services. The right way

Use force endpoints and services, Luke!

Obvious example

$ kubectl get endpoints kubernetes
NAME         ENDPOINTS                                            AGE
kubernetes   192.168.0.1:8443,192.168.0.2:8443,192.168.0.3:8443   1y
$ kubectl get service kubernetes
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.0.0.1     none          443/TCP   1y

In YAML: endpoint

apiVersion: v1
kind: Endpoints
metadata:
  name: kubernetes
  namespace: default
subsets:
- addresses:
  - ip: 192.168.0.1
  - ip: 192.168.0.2
  - ip: 192.168.0.3
  ports:
  - name: https
    port: 8443
    protocol: TCP

In YAML: service

apiVersion: v1
kind: Service
metadata:
  labels:
    component: apiserver
    provider: kubernetes
  name: kubernetes
  namespace: default
spec:
  clusterIP: 10.0.0.1
  ports:
  - name: https
    port: 443
    protocol: TCP
    targetPort: 8443
  type: ClusterIP

Back to PostgreSQL

Endpoint

apiVersion: v1
kind: Endpoints
metadata:
  name: postgres
  namespace: hosted
subsets:
- addresses:
  - ip: 192.168.0.10
  ports:
  - name: postgres
    port: 5432
    protocol: TCP

Service

apiVersion: v1
kind: Service
metadata:
  name: postgres
  namespace: hosted
spec:
  ports:
  - name: postgres
    port: 5432
    protocol: TCP
    targetPort: 5432
  type: ClusterIP

Configuration

export DATABASE_URL='postgresql://application@postgres.hosted.cluster.local:5432/production_db'

./right_way.png

RIGHT!

  • Service address is rock solid
  • Service IP can be preserved in service manifest
  • Any host network reconfiguration is just endpoint upgrade
  • Endpoint upgrade is rocket fast - kube-proxy rocks!

Questions?