Kubernetes - yibinericxia/documents GitHub Wiki

Service

Service Types

There are 3 service types

  • ClusterIP: expose the service on cluster-internal IP address and it is the default service type
  • NodePort: expose the service via a static port on a node
  • LoadBalancer: expose the service via an external load balancer

Headless Service

By setting ClusterIP as "None", it is for creating a service grouping which does not allocate an IP address or forward traffic. It is useful if you host database on a single pod and need service for its restart. The headless service patches the request to the pod without load balancing or routing since it does not have a cluster IP but a new pod IP after restart. It can be used for auto service discovery. Kubernetes allows clients to discover pod IPs through DNS lookup. When the ClusterIP is "None", the DNS server will return the individual pod IPs instead of the service cluster IP thus clients can connect to the pods.

A sample Helm Chart can be configured as follows:

appVersion: v1
kind: Service
metadata:
  name: {{ .Release.Name }}-headless
spec:
  clusterIP: None
  selector:
    key: {{ .Release.Name}}
  ports:
  - protocol: TCP
    port: {{ .Value.api.service.headlessPort }}

with the Value for the above:

api:
  service:
    type: ClusterIP
    headlessPort: 5701 # for Hazelcast

Secret & ConfigMap

Secret

Generate secret for your credential string, such as username, password, etc:

echo -n your-credential-string | base64 -w0

and use it in secretKeyRef section:

valueFrom:
  secretKeyRef:
    name: 
    key: 

ConfigMap

URL mapping

valueFrom:
  configMapKeyRef:
    name: 
    key: