apiVersion: apps/v1
kind: Deployment
metadata:
name: webapp-deployment
labels:
app: webapp
spec:
replicas: 1
selector:
matchLabels:
app: webapp
template:
metadata:
labels:
app: webapp
spec:
containers:
- name: webapp
image: lenmorld/docker-k8s-practice:latest
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: webapp-service
spec:
type: NodePort
selector:
app: webapp
ports:
- port: 3000
protocol: TCP
targetPort: 3000
nodePort: 30100
This specification creates a new Service object named "webapp-service", which targets TCP port 3000 on any Pod with the app=webappl abel.
External service
to expose a Service onto an external IP address, that's outside of your cluster.
by default, services are internal
NodePort
external service type
requires a 3rd port
Node Port - open on k8s node in which the app will be accessible
NodePort range: 30000 - 32767
•
NodePort: Exposes the Service on each Node's IP at a static port (theNodePort). AClusterIPService, to which theNodePortService routes, is automatically created. You'll be able to contact theNodePortService, from outside the cluster, by requesting<NodeIP>:<NodePort>.
https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport