Services Cluster Ip
- A typical fullstack application has the following,
front-end,back-endand a key-value store such asredis. - The
front-endservers need to communicate to theback-endservers and theback-endservers thus need to connect to the key-value store. - All of the
podshave IP addresses assigned to them.- The IPs are not
staticfor thepods.- These IP addresses cannot be relied upon, due to
podsgoing down or new pods coming up etc. - For example, a
front-endpodwith an IP of10.244.0.3needs to connect to one of theback-endpods, which would it connect to?- A Kubernetes
servicecan help group thesepodstogether and help to access the services as a group.- For example, a
servicecan group all of theback-endpods together and create a single service to group all of theback-endpodstogether.- Any requests to the
back-endpodswould be assigned to a pod at random.- A similar
servicecould be used to group theredispods together in a similar way.
- A similar
- Any requests to the
- For example, a
- A Kubernetes
- These IP addresses cannot be relied upon, due to
- The IPs are not
- Each
serviceis given a name and IP. - To create a
ClusterIPservice, here is an example definition file: ``` apiVersion: v1 kind: Service metadata: name: back-end
spec: type: ClusterIP ports: - targetPort: 80 port: 80
selector:
app: myapp
type: back-end ``` * `ClusterIP` is the default `type`, so even if you do not specify `ClusterIP` under `spec`, that will be the default chosen anyway. * The `app` and `type` fields are copied from the `pod` definition file. * The service is then created with `kubectl create -f <service>.yaml`. * Check the service with `kubectl get services`