Services enable communication within and outside of our application. Helps connect different applications or users.
NodePort: External access to the node(30000-32767)
apiVersion: v1
kind: Service
metadata:
name: my-app-service
spec:
type: NodePort
ports:
- targetPort: 80
// port of node
port: 80 //Service port
nodePort: 30008 //
//port and nodePort are optional. port=targetPort and nodePort is randomly assigned
selector: //inorder to select the concerned pod(s)
app: myapp
type: front-end
kubectl get services
//list services
ClusterIP:
apiVersion: v1
kind: Service
metadata:
name: my-app-service
spec:
type: ClusterIP
ports:
- targetPort: 80
// port of node
port: 80 //Service port
selector: //inorder to select the concerned pod(s)
app: myapp
type: front-end
LoadBalancer:
apiVersion: v1
kind: Service
metadata:
name: my-app-service
spec:
type: LoadBalancer
ports:
- targetPort: 80
// port of node
port: 80 //Service port
nodePort: 30008
selector: //inorder to select the concerned pod(s)
app: myapp
type: front-end