Skip to content

godarikx/k8s-services-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kubernetes Service Types Demo

This project demonstrates four main types of Kubernetes services:

  • ClusterIP - Internal cluster service
  • NodePort - Access via node port
  • LoadBalancer - External load balancer
  • ExternalName - DNS CNAME for external services

Kubernetes Services Overview

Project Structure

k8s-service/
├── clusterip/          # ClusterIP service
├── nodeport/           # NodePort service
├── loadbalancer/       # LoadBalancer service
├── externalname/       # ExternalName service
└── README.md           # This file

Requirements

Quick Start

1. ClusterIP - Internal Service

# Installation
helm install clusterip-demo ./clusterip

# Verification
kubectl get svc clusterip-demo-clusterip-service

# Testing (create a test pod)
kubectl run test-pod --image=curlimages/curl -it --rm --restart=Never -- sh
# Inside pod: curl http://clusterip-demo-clusterip-service

# Or via port-forward
kubectl port-forward svc/clusterip-demo-clusterip-service 8080:80
curl http://localhost:8080

Features: Only accessible inside the cluster, used for internal pod communication.

2. NodePort - Access via Node

# Installation
helm install nodeport-demo ./nodeport

# Verification
kubectl get svc nodeport-demo-nodeport-service

# Get NodePort and node IP
NODE_PORT=$(kubectl get svc nodeport-demo-nodeport-service -o jsonpath='{.spec.ports[0].nodePort}')
NODE_IP=$(kubectl get nodes -o jsonpath='{.items[0].status.addresses[?(@.type=="InternalIP")].address}')

# Testing
curl http://$NODE_IP:$NODE_PORT

# For minikube
minikube service nodeport-demo-nodeport-service

Features: Accessible externally via any node IP on port 30000-32767.

3. LoadBalancer - External Load Balancer

# Installation
helm install loadbalancer-demo ./loadbalancer

# Verification (wait for EXTERNAL-IP)
kubectl get svc loadbalancer-demo-loadbalancer-service
watch kubectl get svc loadbalancer-demo-loadbalancer-service

# Testing (after getting EXTERNAL-IP)
EXTERNAL_IP=$(kubectl get svc loadbalancer-demo-loadbalancer-service -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
curl http://$EXTERNAL_IP

# For minikube (requires minikube tunnel)
minikube tunnel  # In a separate terminal

Features: Automatically creates external load balancer (in cloud) or requires minikube tunnel (locally).

4. ExternalName - External DNS

# Installation
helm install externalname-demo ./externalname

# Verification
kubectl get svc externalname-demo-externalname-service

# Testing (use test pod)
kubectl exec -it externalname-demo-externalname-service-test -- sh
# Inside pod:
nslookup externalname-demo-externalname-service
curl -v http://externalname-demo-externalname-service

Features: Creates DNS CNAME to external service, allows using local name instead of external domain.

Service Types Comparison

Type Availability Use Case Performance
ClusterIP Inside cluster only Internal pod-to-pod communication High
NodePort Via node IP, port 30000-32767 Development, testing Medium
LoadBalancer External IP (cloud) Production, public services High
ExternalName DNS CNAME to external service Integration with external services Depends on external service

Uninstalling All Demos

helm uninstall clusterip-demo
helm uninstall nodeport-demo
helm uninstall loadbalancer-demo
helm uninstall externalname-demo

Demonstration

After deploying each service type, run the following commands to verify:

ClusterIP

  • ✅ Accessible via DNS name inside cluster
  • ✅ Not accessible externally without port-forward
  • ✅ Uses internal cluster IP

NodePort

  • ✅ Accessible via any node IP
  • ✅ Port in range 30000-32767
  • ✅ Works without additional configuration

LoadBalancer

  • ✅ Gets external IP automatically in cloud
  • ✅ Requires configuration in local clusters (minikube tunnel)
  • ✅ Suitable for production

ExternalName

  • ✅ Creates DNS CNAME record
  • ✅ Allows accessing external services via local name
  • ✅ Does not proxy traffic, only DNS resolution

Configuration

All subprojects support Docker registry configuration via values.yaml:

image:
  registry: ""  # Use Docker Hub directly (default)
  # registry: localhost:<PORT>  # For local registry
  repository: nginx
  pullPolicy: IfNotPresent
  tag: "1.25"

If registry is not specified (empty string), images will be pulled directly from Docker Hub or other public registries.

Additional Resources

About

Demonstration of Kubernetes service types (ClusterIP, NodePort, LoadBalancer, ExternalName) using Helm charts. Ready-to-use examples for learning and testing.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages