Configure Kubernetes Services for networking and load balancing in your cluster
This skill helps you configure Kubernetes Services to expose applications running in your cluster, enabling networking and load balancing between pods and external traffic.
Guides you through creating and managing Kubernetes Services to:
When a user requests help with Kubernetes Services, follow these steps:
1. **Understand the requirements**
- Ask what application needs to be exposed
- Determine if the service is for internal cluster access or external traffic
- Identify the target pods using labels
- Determine which ports need to be exposed
2. **Choose the appropriate Service type**
- **ClusterIP** (default): Internal cluster access only
- **NodePort**: Exposes service on each node's IP at a static port
- **LoadBalancer**: Creates external load balancer (cloud provider required)
- **ExternalName**: Maps service to external DNS name
3. **Create the Service manifest**
- Define metadata (name, namespace, labels)
- Specify the service type
- Configure selectors to target pods
- Map service ports to target container ports
- Add any additional configuration (sessionAffinity, externalTrafficPolicy, etc.)
4. **Apply the configuration**
- Use `kubectl apply -f service.yaml` to create the service
- Verify with `kubectl get services` and `kubectl describe service <name>`
- Test connectivity from within the cluster or externally as appropriate
5. **Configure DNS and discovery**
- Explain the DNS name format: `<service-name>.<namespace>.svc.cluster.local`
- Show how other pods can access the service
- Document environment variables automatically injected
6. **Set up load balancing (if applicable)**
- Configure sessionAffinity for sticky sessions if needed
- Set externalTrafficPolicy for traffic routing behavior
- Configure health checks via readiness probes on pods
7. **Implement network policies (optional)**
- Add NetworkPolicy resources to control traffic flow
- Restrict access to specific namespaces or pods
- Document security boundaries
8. **Provide troubleshooting guidance**
- Check service endpoints: `kubectl get endpoints <service-name>`
- Verify pod selectors match running pods
- Test DNS resolution from within cluster
- Check firewall rules for NodePort/LoadBalancer services
**Basic ClusterIP Service:**
```yaml
apiVersion: v1
kind: Service
metadata:
name: my-app
namespace: default
spec:
type: ClusterIP
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 8080
```
**LoadBalancer Service:**
```yaml
apiVersion: v1
kind: Service
metadata:
name: my-app-external
spec:
type: LoadBalancer
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 8080
externalTrafficPolicy: Local
```
**Service with multiple ports:**
```yaml
apiVersion: v1
kind: Service
metadata:
name: multi-port-service
spec:
selector:
app: my-app
ports:
- name: http
protocol: TCP
port: 80
targetPort: 8080
- name: https
protocol: TCP
port: 443
targetPort: 8443
```
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/kubernetes-services-setup/raw