+
sql
+
+
+
bitbucket
xcode
+
clickhouse
+
+
mocha
===
+
ray
cassandra
+
websocket
mvn
^
+
+
+
clion
+
rs
+
goland
+
android
+
+
bsd
pip
strapi
elm
+
cosmos
qwik
!
+
+
surrealdb
+
spacy
โˆ‘
+
vscode
nest
svelte
+
+
yarn
raspbian
koa
c
pascal
+
+
graphdb
*
+
raspbian
+
+
android
hapi
$
+
py
@
azure
+
+
cargo
+
+
helm
+
+
netlify
+
+
sse
+
+
webstorm
+
ฮป
Back to Blog
๐Ÿš€ Setting Up Kubernetes Services: Simple Guide
Alpine Linux Kubernetes Containers

๐Ÿš€ Setting Up Kubernetes Services: Simple Guide

Published May 31, 2025

Easy tutorial for beginners to set up Kubernetes services on Alpine Linux. Perfect for container networking with step-by-step instructions and clear examples.

9 min read
0 views
Table of Contents

๐Ÿš€ Setting Up Kubernetes Services: Simple Guide

Letโ€™s set up Kubernetes services on your Alpine Linux system! โš™๏ธ This guide uses easy steps and simple words. Weโ€™ll connect your containers to the network! ๐Ÿ˜Š

๐Ÿค” What are Kubernetes Services?

Kubernetes services are like postal addresses that help containers find each other!

Think of services like:

  • ๐Ÿ“ A phone book that connects container names to addresses
  • ๐Ÿ”ง A network bridge that routes traffic between containers
  • ๐Ÿ’ก A system that makes containers easy to reach

๐ŸŽฏ What You Need

Before we start, you need:

  • โœ… Alpine Linux system running
  • โœ… Kubernetes cluster already set up
  • โœ… kubectl command line tool installed
  • โœ… Basic knowledge of containers

๐Ÿ“‹ Step 1: Check Kubernetes Status

Verify Cluster is Running

First, letโ€™s make sure Kubernetes is working! ๐Ÿ˜Š

What weโ€™re doing: Checking that your Kubernetes cluster is healthy and ready for services.

# Check cluster status
kubectl cluster-info

# List all nodes
kubectl get nodes

# Check system pods
kubectl get pods -n kube-system

What this does: ๐Ÿ“– Shows you the current state of your Kubernetes cluster.

Example output:

Kubernetes control plane is running at https://192.168.1.100:6443
CoreDNS is running at https://192.168.1.100:6443/api/v1/...

NAME           STATUS   ROLES           AGE   VERSION
alpine-master  Ready    control-plane   1d    v1.28.0
alpine-worker  Ready    <none>          1d    v1.28.0

NAME                              READY   STATUS    RESTARTS   AGE
coredns-5d78c9869d-abc123         1/1     Running   0          1d
kube-proxy-xyz789                 1/1     Running   0          1d

What this means: Your Kubernetes cluster is ready for services! โœ…

๐Ÿ’ก Important Tips

Tip: Services work at the cluster level, not just single nodes! ๐Ÿ’ก

Warning: Make sure all nodes are โ€œReadyโ€ before creating services! โš ๏ธ

๐Ÿ› ๏ธ Step 2: Create Your First Service

Deploy a Simple Application

Now letโ€™s create an application that needs a service! ๐Ÿ˜Š

What weโ€™re doing: Setting up a simple web application that we can expose through a service.

# Create a simple nginx deployment
kubectl create deployment nginx-app --image=nginx:alpine

# Check if deployment is ready
kubectl get deployments
kubectl get pods

Create a deployment file for better control:

# Save as nginx-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-app
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:alpine
        ports:
        - containerPort: 80

Apply the deployment:

# Apply the deployment
kubectl apply -f nginx-deployment.yaml

# Wait for pods to be ready
kubectl wait --for=condition=ready pod -l app=nginx

What this means: You have a web application running in containers! ๐ŸŽ‰

๐ŸŽฎ Step 3: Create a ClusterIP Service

Internal Service for Pods

Letโ€™s create a service to connect your containers! ๐ŸŽฏ

What weโ€™re doing: Creating a ClusterIP service that allows pods to communicate with each other.

# Create service using kubectl
kubectl expose deployment nginx-app --port=80 --target-port=80 --type=ClusterIP

# Check the service
kubectl get services

Or create a service file for more control:

# Save as nginx-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
  labels:
    app: nginx
spec:
  type: ClusterIP
  ports:
  - port: 80
    targetPort: 80
    protocol: TCP
  selector:
    app: nginx

Apply the service:

# Apply the service
kubectl apply -f nginx-service.yaml

# Check service details
kubectl describe service nginx-service

You should see:

NAME            TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
nginx-service   ClusterIP   10.96.123.45    <none>        80/TCP    30s

Name:              nginx-service
Namespace:         default
Selector:          app=nginx
Type:              ClusterIP
IP Family:         IPv4
IP:                10.96.123.45
Port:              <unset>  80/TCP
TargetPort:        80/TCP
Endpoints:         10.244.1.5:80,10.244.1.6:80,10.244.2.7:80

Great job! Your internal service is working! ๐ŸŒŸ

๐Ÿ“Š Step 4: Test Service Communication

Verify Service is Working

Now letโ€™s test that the service connects to pods! ๐Ÿ˜Š

What weโ€™re doing: Testing that the service properly routes traffic to your application pods.

# Test service from inside the cluster
kubectl run test-pod --image=alpine --rm -it -- sh

# Inside the test pod, try these commands:
# wget -qO- nginx-service
# wget -qO- nginx-service.default.svc.cluster.local
# exit

Test with curl from another pod:

# Create a test pod with curl
kubectl run curl-test --image=curlimages/curl --rm -it -- sh

# Test the service (inside the pod)
curl http://nginx-service
curl http://nginx-service.default.svc.cluster.local

Expected output:

<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
...

Awesome work! Your service is routing traffic correctly! ๐ŸŒŸ

๐ŸŽฎ Letโ€™s Try It!

Time for hands-on practice! This is the fun part! ๐ŸŽฏ

What weโ€™re doing: Creating different types of services to understand how they work.

# Check current services
kubectl get services -o wide

# Get service endpoints
kubectl get endpoints nginx-service

# Test service from different namespaces
kubectl create namespace test-ns
kubectl run test-curl -n test-ns --image=curlimages/curl --rm -it -- curl http://nginx-service.default.svc.cluster.local

You should see:

NAME            TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE   SELECTOR
nginx-service   ClusterIP   10.96.123.45    <none>        80/TCP    5m    app=nginx

NAME            ENDPOINTS                                   AGE
nginx-service   10.244.1.5:80,10.244.1.6:80,10.244.2.7:80 5m

Awesome work! You understand how services work! ๐ŸŒŸ

๐Ÿ“Š Quick Summary Table

Service TypeUse CaseAccess FromExample
๐Ÿ”ง ClusterIPInternal onlyInside clusternginx-service
๐Ÿ› ๏ธ NodePortExternal accessAny node IPnginx-service:30080
๐ŸŽฏ LoadBalancerCloud externalInternetExternal IP
๐Ÿš€ ExternalNameExternal serviceDNS redirectexternal-db

๐ŸŒ Step 5: Create External Services

NodePort Service for External Access

Letโ€™s create a service that people can reach from outside! ๐ŸŒ

What weโ€™re doing: Creating a NodePort service that allows external access to your application.

# Save as nginx-nodeport.yaml
apiVersion: v1
kind: Service
metadata:
  name: nginx-nodeport
  labels:
    app: nginx
spec:
  type: NodePort
  ports:
  - port: 80
    targetPort: 80
    nodePort: 30080
    protocol: TCP
  selector:
    app: nginx

Apply and test:

# Apply the NodePort service
kubectl apply -f nginx-nodeport.yaml

# Check the service
kubectl get services nginx-nodeport

# Test from outside the cluster
curl http://NODE_IP:30080
# Replace NODE_IP with your actual node IP

What this does: Makes your application available on port 30080 of every node! ๐Ÿ“š

Example: LoadBalancer Service ๐ŸŸก

What weโ€™re doing: Creating a LoadBalancer service for cloud environments.

# Save as nginx-loadbalancer.yaml
apiVersion: v1
kind: Service
metadata:
  name: nginx-loadbalancer
  labels:
    app: nginx
spec:
  type: LoadBalancer
  ports:
  - port: 80
    targetPort: 80
    protocol: TCP
  selector:
    app: nginx

Apply and check:

# Apply LoadBalancer service
kubectl apply -f nginx-loadbalancer.yaml

# Check for external IP (may take time)
kubectl get services nginx-loadbalancer

What this does: Creates an external load balancer (in cloud environments)! ๐ŸŒŸ

๐Ÿšจ Fix Common Problems

Problem 1: Service not finding pods โŒ

What happened: Service has no endpoints. How to fix it: Check pod labels and selectors!

# Check pod labels
kubectl get pods --show-labels

# Check service selector
kubectl describe service nginx-service

# Fix label mismatch
kubectl label pods POD_NAME app=nginx

Problem 2: Canโ€™t reach service โŒ

What happened: Service exists but not accessible. How to fix it: Check network and firewall!

# Check service endpoints
kubectl get endpoints nginx-service

# Test service resolution
nslookup nginx-service.default.svc.cluster.local

# Check iptables rules
iptables -L -t nat | grep nginx

Problem 3: External access not working โŒ

What happened: NodePort service canโ€™t be reached externally. How to fix it: Check node firewall and network!

# Check if port is open on node
netstat -tlnp | grep :30080

# Test from node itself
curl localhost:30080

# Check firewall rules
iptables -L | grep 30080

Donโ€™t worry! These problems happen to everyone. Youโ€™re doing great! ๐Ÿ’ช

๐Ÿ’ก Simple Tips

  1. Use meaningful names ๐Ÿ“… - Name services clearly
  2. Match selectors carefully ๐ŸŒฑ - Labels must match exactly
  3. Test from inside first ๐Ÿค - Verify internal connectivity
  4. Monitor service health ๐Ÿ’ช - Check endpoints regularly

โœ… Check Everything Works

Letโ€™s make sure everything is working:

# List all services
kubectl get services -o wide

# Check service endpoints
kubectl get endpoints

# Test internal connectivity
kubectl run test-curl --image=curlimages/curl --rm -it -- curl nginx-service

# Check external access (if using NodePort)
curl http://NODE_IP:30080

# Verify service discovery
kubectl exec -it test-pod -- nslookup nginx-service

# You should see this
echo "Kubernetes services are working! โœ…"

Good output:

NAME            TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
nginx-service   ClusterIP   10.96.123.45    <none>        80/TCP         10m
nginx-nodeport  NodePort    10.96.234.56    <none>        80:30080/TCP   5m

NAME            ENDPOINTS                                   AGE
nginx-service   10.244.1.5:80,10.244.1.6:80,10.244.2.7:80 10m

<!DOCTYPE html>
<html><head><title>Welcome to nginx!</title>
โœ… Success! All services are working perfectly.

๐Ÿ† What You Learned

Great job! Now you can:

  • โœ… Create and manage Kubernetes services
  • โœ… Set up internal ClusterIP services for pod communication
  • โœ… Configure external NodePort services for outside access
  • โœ… Test and troubleshoot service connectivity
  • โœ… Understand different service types and their use cases

๐ŸŽฏ Whatโ€™s Next?

Now you can try:

  • ๐Ÿ“š Setting up Ingress controllers for advanced routing
  • ๐Ÿ› ๏ธ Creating service meshes for microservices
  • ๐Ÿค Implementing service monitoring and health checks
  • ๐ŸŒŸ Building multi-cluster service communication!

Remember: Every expert was once a beginner. Youโ€™re doing amazing! ๐ŸŽ‰

Keep practicing and youโ€™ll become a Kubernetes expert too! ๐Ÿ’ซ