Introduction to Kubernetes Core Concepts, Networking, Services and Workloads
This article provides a comprehensive overview of Kubernetes, covering its core components such as Nodes, Pods, Services, Namespaces, Deployments, StatefulSets, Jobs and CronJobs, as well as detailed explanations of Pod networking, Service types (ClusterIP, NodePort, LoadBalancer) and practical YAML examples for each resource.
Kubernetes (K8s) is an open‑source container orchestration system originally developed by Google. It manages containerised applications and provides features such as cluster management, automatic scaling, Service handling and load balancing.
Core concepts include:
Node : the smallest unit of a Kubernetes cluster, a set of machines that run applications and store data.
Pod : the executable unit in Kubernetes that contains one or more containers, networking and storage resources.
Service : an abstraction that defines how to access a group of Pods, exposing them internally or externally.
Namespace : a logical partition within a cluster that isolates resources for different environments or teams.
Deployment : manages a set of Pods via ReplicaSets, handling scaling, rolling updates and rollbacks.
StatefulSet : ensures ordered, unique Pod identities, typically used for stateful applications like databases.
Job : runs one‑off or batch tasks to completion, creating Pods that terminate after the task finishes.
CronJob : schedules Jobs to run periodically using cron‑style expressions.
Pod networking
Kubernetes assigns each Pod an IP address, allowing seamless communication across Nodes. Two main network models are supported:
Bridge network : simple intra‑Node communication between Pods and other containers.
Tunnel network : enables cross‑Node communication and external service access.
Network plugins such as Calico or Flannel provide IP allocation, external connectivity, IPVS and DNS support. Example of installing Flannel:
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.ymlTo view a Pod’s IP address: kubectl get pods --show-labels Cross‑Node communication can be tested with tools like nc between Pods.
Service types
ClusterIP (default) creates an internal virtual IP reachable only within the cluster.
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: MyApp
ports:
- protocol: TCP
port: 80
targetPort: 80
type: ClusterIP
EOFNodePort exposes a Service on a static port on each Node, allowing external access via <NodeIP>:<NodePort>. Example:
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Service
metadata:
name: nodeport-service
spec:
selector:
app: MyApp
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 30000
type: NodePort
EOFLoadBalancer provisions an external load balancer (cloud provider dependent) to expose the Service. Example:
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Service
metadata:
name: loadbalancer-service
spec:
selector:
app: MyApp
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
EOFTesting a Service can be done by creating a test Pod and curling the Service DNS name, e.g. kubectl run test --image=nginx:latest followed by
kubectl exec test -- curl my-service.default.svc.cluster.local.
Namespace usage
Namespaces isolate resources such as Pods, Services and Volumes. Common commands:
kubectl get namespaces kubectl create namespace developmentDeployment example
cat <<EOF | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
replicas: 3
selector:
matchLabels:
app: MyApp
template:
metadata:
labels:
app: MyApp
spec:
containers:
- name: nginx
image: nginx:1.7.9
EOFCheck rollout status: kubectl rollout status deployment/my-deployment Update the image: kubectl set image deployment/my-deployment nginx=nginx:1.8.0 StatefulSet example
cat <<EOF | kubectl apply -f -
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: my-statefulset
spec:
serviceName: "my-service"
replicas: 3
selector:
matchLabels:
app: MyApp
template:
metadata:
labels:
app: MyApp
spec:
containers:
- name: my-app
image: nginx:1.7.9
EOFList StatefulSets and Pods:
kubectl get statefulsets kubectl get pods --selector=app=MyAppJob example
cat <<EOF | kubectl apply -f -
apiVersion: batch/v1
kind: Job
metadata:
name: my-job
spec:
template:
spec:
containers:
- name: my-container
image: ubuntu
command: ["sh", "-c", "echo Hello from the job; sleep 5"]
restartPolicy: Never
EOFCheck job status: kubectl get jobs CronJob example (runs hourly)
cat <<EOF | kubectl apply -f -
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: hello
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox
args:
- /bin/sh
- -c
- "date; echo Hello from the Kubernetes cluster"
restartPolicy: OnFailure
EOFThis CronJob creates a Job each hour that prints the current date and a greeting message.
All the above examples illustrate how Kubernetes resources are defined with YAML manifests and managed via kubectl commands, enabling scalable, reliable and automated deployment of containerised workloads.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
