Kubernetes Networking contd…
Internet/External to Service Networking (contd)
- Routing traffic to Kubernetes (Ingress)
- Layer 4: Load Balancer
- Layer 7: Ingress Controller
Layer 4 Load Balancer
- When we create a k8s service, we can specify the type LoadBalancer. The implementation of Load Balancer is given by cloud controller which knows how to create a load balancer for your service

Kubernetes Service
Node Port
- This service provides a simple way for external software to route traffic to pods
- Nodeport service exposes a fixed port on all nodes, which routes to applicable pods.
nodePort
(.spec.ports[].nodePort) field specify the port to be opened all all nodes for the corresponding port on Pods
- While creating the service if we leave
nodePort
field empty k8s will automatically selects a unique port 30000-32767
- nginx deployment
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 2
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
- Lets use nginx with nodePort
---
apiVersion: v1
kind: Service
metadata:
name: nginx-svc
spec:
type: NodePort
selector:
app: nginx
ports:
- name: nginx-svc
protocol: TCP
port: 80
targetPort: 80
nodePort: 30000

- We will try LoadBalancer and ExternalName in future sessions
- Note: K8s doesnot have an inbuilt layer 7 load balancer, so we need to understand ingress and ingress controller.
Like this:
Like Loading...