Lab 4.1 - Serviços ClusterIP e NodePort
Objetivos
Ao final deste lab, você será capaz de:
- Criar Serviços ClusterIP
- Criar Serviços NodePort
- Verificar Endpoints
- Testar a conectividade
Exercício 1: Serviço ClusterIP
Etapa 1: Criar um Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-deployment
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: nginx
image: nginx:1.20
Etapa 2: Criar um Serviço ClusterIP
apiVersion: v1
kind: Service
metadata:
name: web-service
spec:
type: ClusterIP
selector:
app: web
ports:
- port: 80
targetPort: 80
Etapa 3: Testar
# Ver o Serviço
kubectl get service web-service
# Ver os Endpoints
kubectl get endpoints web-service
# Testar a partir de um Pod
kubectl run test-pod --image=busybox --rm -it -- sh
# No Pod: wget -O- http://web-service
Exercício 2: Serviço NodePort
Etapa 1: Criar um Serviço NodePort
apiVersion: v1
kind: Service
metadata:
name: web-nodeport
spec:
type: NodePort
selector:
app: web
ports:
- port: 80
targetPort: 80
nodePort: 30080
Etapa 2: Testar
# Ver o Serviço
kubectl get service web-nodeport
# Acessar via NodePort
# curl http://<node-ip>:30080
Limpeza
kubectl delete deployment web-deployment
kubectl delete service web-service web-nodeport
Próximos Passos
Lab 4.2: Descoberta de Serviços com DNS
Lab criado em: Dezembro 2024