K8s services
In Kubernetes, a Service is a method for exposing a network application that is running as one or more Pods in your cluster.
Problem to tackle: with many nodes and pods of applications, how would the applications contact each other?
apiVersion: v1
kind: Service
metadata:
name: myapp-service
spec:
type: NodePort
ports:
- targetPort: 80
port: 80
nodePort: 30008 # range between 30000 - 32767
selector:
app: nginx
type: nginx
apiVersion: v1
kind: Service
metadata:
name: back-end
spec:
type: ClusterIP # default
ports:
- targetPort: 80
port: 80
selector:
app: myapp
type: back-end
apiVersion: v1
kind: Service
metadata:
name: back-end
spec:
type: LoadBalancer
ports:
- targetPort: 80
port: 80
nodePort: 30008 # range between 30000 - 32767