Kubernetes Tutorial for Beginners: Basics, Architecture and Beyond

[…]

A Deep Dive into Kubernetes Objects

Let‘s build familiarity with some of the fundamental Kubernetes object manifests through examples…

Simple Pod Definition

Here is basic Pod configuration running nginx container exposed on port 80:

apiVersion: v1
kind: Pod 
metadata:
  name: nginx
spec:
  containers:
  - name: nginx 
    image: nginx
    ports:
    - containerPort: 80

Notice the apiVersion, kind, metadata, spec in Kubernetes object definitions. This helps validate, consume and operate on those resources.

Deployment for Replicated Pods

For replicated pods, we use Deployments that maintain a stable replica set even during updates:

apiVersion: apps/v1
kind: Deployment 
metadata:
  name: nginx-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2 
        ports:
        - containerPort: 80

Here we configure 3 pod replicas governed by a nginx-deployment. MatchLabels allow grouping pods.

Similarly, have defined other objects like StatefulSets, DaemonSets, Jobs, CronJobs for specialized use cases.

Setting Resource Limits

We can set CPU/Memory limits, requests and vertical pod autoscaling thresholds:

resources:
      limits:
        memory: "128Mi" 
        cpu: "500m"
      requests:
        memory: "64Mi"
        cpu: "250m"

This allows overcommitting hosts and restricting container usage if needed. […]

Helm Charts to Package Applications

Helm streamlines deploying complex, multi-services applications on Kubernetes. Predefined Charts allow packaging entire stack configurations, dependencies and parameters.

For example, a media wiki Helm chart bundles together – deployment, service, ingress controller and database containers to provision entire wiki site through configuration values.

Network and Service Discovery

Kubernetes enables networking between various containers […]

Here are some ways Kubernetes provides networking facilities:

CNI and kube-proxy enable pod connectivity […]

Services expose backend working pods through stable endpoints […]

Ingress acts as HTTP routers mapping domains [..]

Persistent Storage and Data

Storage abstractions in Kubernetes […]

Volumes provide ephemeral storage tied to pod lifecycles useful for sharing files […]

For durable storage independent of pod recreation, PersistentVolumes allow […]

StatefulSets run replicated databases […]

We can also offload backup/disaster recovery of Kubernetes state itself onto storage systems.

Integrating CI/CD Pipelines

Kubernetes native APIs make it easy to embed it as part of modern CI/CD frameworks […]

For example, configure a Jenkins Pipeline to –

  • Build and validate Docker images
  • Push images to registry
  • Generate Kubernetes deployment manifests
  • Apply changes through kubectl onto clusters

This enables infrastructure-as-code through CI automation.

Monitoring, Logs and Debugging

Robust observability is must for production-grade Kubernetes […]

Metrics Server addon exposesCPU/memory usage statistics for pods & nodes.

Prometheus operator simplifies configuring Prometheus servers to scrape metrics endpoints. AlertManager handles alerts.

Logging layers like Fluentd ship container logs to data stores. ElasticSearch powers log analytics and visualization.

Kubernetes auditing provides audit trail of internal events and API requests.

kubectl cluster-info dump

Helps take debug dumps of cluster state.

Now that you have […]

Read More Topics