Mega Menu

Sunday, March 08, 2020

Kubernetes ClusterIP Basic YAML

ClusterIP is a logical grouping of similar containers for inter-communication between containers on a Pod.
eg: clusterIp for database container for use by container having backend logic


service-def.yml

apiVersion: v1
kind: Service
metadata:
  name: image-processing
  labels:
    app: myapp
spec:
  type: ClusterIP
  ports:
    - port: 80     (port on the ClusterIP service)
      targetPort: 8080   (port on the target container)
  selector:
    tier: backend

Kubernetes NodePort basic yaml


Basic Flow:

         

  

service-definition.yml
apiVersion: v1
kind: Service
metadata:
  name: myapp-service
spec:
  type: NodePort   
  ports:
    - targetPort: 80
      port: 80   (container port)
      nodePort: 30008   (Port of node)
  selector:
    app: myapp
    type: front-end
   

kubectl create -f  service-definition.yml   
   
kubectl get services   


When multiple pods are deployed on a single node, Kubernetes does a makes sure to randomly route the traffic to matching pods.

When multiple nodes exist in a cluster with this pod spun across multiple nodes, Kubernetes creates a service across nodes to ensure the nodeport routing is consistent.