Tutorials  /  Container & Cloud

Diving into the World of Kubernetes

Ccentron Redaktion · November 2024 ·4 min read ·Container & Cloud, Tutorial

From foundational concepts to practical applications – dive in and expand your understanding of Kubernetes. We guide you through the multifaceted world of this container orchestration tool.

In this tutorial, we explore the fundamental concepts of Kubernetes. Using an example, we’ll also demonstrate the process of deploying, exposing, and scaling applications.

Basics

Before diving deeper, it’s essential to understand the basic building blocks of Kubernetes:

  • Cluster: A pool of compute, storage, and network resources.
  • Nodes: Host machines within the cluster.
  • Namespaces: Logical partitions of a cluster.
  • Pods: Units of deployment.
  • Labels and Selectors: Key-value pairs for identification and service discovery.
  • Services: Collection of Pods belonging to the same application.
  • Replica Set: Ensures availability and scalability.
  • Deployment: Manages the application lifecycle.

In-Depth Analysis

A Kubernetes cluster consists of Nodes that serve as hosts for Pods. Pods are the basic units of deployment and can contain one or more containers. Services allow Pods to be exposed, while Labels and Selectors help identify and link objects.

Application

With an understanding of the basics, we can begin deployment. A straightforward step-by-step process helps develop a better understanding.

1. Listing Kubernetes Nodes and Namespaces

Check the available Nodes and Namespaces using the appropriate commands.

kubectl get nodes

kubectl get namespaces

2. Creating and Deploying a Pod

Define a Pod in a YAML file and create it with the command `kubectl create -f filename.yaml`.

# Simple-Pod.yaml

apiVersion: "v1"

kind: Pod

metadata:

name: web-pod

labels:

name: web

env: dev

spec:

containers:

- name: myweb

image: nginx

ports:

- containerPort: 80

name: http

protocol: TCP

kubectl create -f Simple-Pod.yaml

3. Exposing Pods via a Service

Define a Service to make a Pod publicly accessible.

# Simple-Service.yaml

apiVersion: v1

kind: Service

metadata:

name: web-svc

labels:

name: web

env: dev

spec:

selector:

name: web

type: NodePort

ports:

- port: 80

name: http

targetPort: 80

protocol: TCP

kubectl create -f Simple-Service.yaml

4. Scaling Pods with a Replica Set

Create a Replica Set to ensure a specific number of Pods are running in the cluster.

# Simple-RS.yaml

apiVersion: apps/v1

kind: ReplicaSet

metadata:

name: web-rs

labels:

name: web

env: dev

spec:

replicas: 3

selector:

matchLabels:

name: web

template:

metadata:

labels:

name: web

env: dev

spec:

containers:

- name: myweb

image: nginx

ports:

- containerPort: 80

name: http

protocol: TCP

kubectl create -f Simple-RS.yaml

5. Working with Deployments

Use Deployments to simplify application updates and patching, ensuring minimal downtime.

# Simple-Deployment.yaml

apiVersion: apps/v1

kind: Deployment

metadata:

name: web-dep

labels:

name: web

env: dev

spec:

replicas: 3

selector:

matchLabels:

name: web

template:

metadata:

labels:

name: web

spec:

containers:

- name: myweb

image: nginx

ports:

- containerPort: 80

kubectl create -f Simple-Deployment.yaml

Jetzt 200 € Guthaben sichern

Testen Sie Ihr Setup auf ccloud³

Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.

centron Redaktion Technische Redaktion

Das Redaktionsteam von centron schreibt Anleitungen aus dem Betriebsalltag: getestet auf unserer eigenen Plattform, betrieben im Rechenzentrum in Hallstadt bei Bamberg.

Kategorie Container & Cloud
Teilen
Noch offene Fragen?

Unser Team hilft Ihnen bei Ihrem konkreten Setup weiter – von Menschen, die die Plattform selbst betreiben.

War dieses Tutorial hilfreich?

Ihre Antwort wird anonym gespeichert und hilft uns, die Tutorials zu verbessern.

Kommentare

Noch keine Kommentare – stellen Sie die erste Frage zu diesem Tutorial.

Zum Kommentieren anmelden

Kommentare stehen centron-Kunden offen. Melden Sie sich in Ihrem Konto an, um eine Frage zu diesem Tutorial zu stellen.

Weiterlesen

Das könnte Sie auch interessieren

Jetzt kostenlos anfangen

Melden Sie sich an und erhalten Sie in den ersten 60 Tagen ein Guthaben von 200 € bei centron.

Dieses Werbeangebot gilt nur für neue Konten. Angebot ausschließlich für Gewerbetreibende.

Jetzt loslegen Sales kontaktieren