Configuring Application Access with a NodePort Service
Create a deployment named:
lab155deploy
kubectl create deployment lab155deploy --image=nginx
kubectl scale deployment lab155deploy --replicas=3
kubectl get deploy
kubectl expose deployment lab155deploy \ --port=80 \ --target-port=80 \ --type=NodePort \ --dry-run=client -o yaml > svc.yaml
Edit the YAML and add the NodePort value.
apiVersion: v1
kind: Service
metadata:
name: lab155deploy
spec:
type: NodePort
selector:
app: lab155deploy
ports:
- port: 80
targetPort: 80
nodePort: 32567
kubectl apply -f svc.yaml
kubectl get deploy
kubectl get svc
kubectl describe svc lab155deploy
kubectl get endpoints lab155deploy
Deployment: 3/3 Running
Service Type: NodePort
NodePort: 32567
Endpoints: 192.168.235.191:80 192.168.235.142:80 192.168.189.78:80
You discovered a common exam confusion:
curl http://10.108.40.57:32567
This does NOT test the NodePort correctly because:
Correct NodePort tests:
curl http://172.31.4.33:32567
curl http://172.31.8.139:32567
curl http://172.31.12.53:32567
External Access
↓
NodePort Service
↓
type: NodePort
↓
nodePort: 32567
Three things the grader will likely check: