Skip to content

Kubernetes main concepts and commands

Published:

Overview

Kubernetes is a portable and open-source platform for managing containerized workloads and services. When you deploy Kubernetes, you get a cluster.

Nodes and Pods

A Kubernetes cluster consists of many machines, called nodes, that run containerized applications. Every cluster has at least one master node that orchestrate the other ones.

The worker nodes host one or more pods that are the components of the application workload, usually a pod contain one service (server application, db, nginx, etc…)

template

pod-definition.yml

apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app: myapp
    type: frontend
spec:
  metadata:
    labels:
      tier: frontend
  spec:
    containers:
    - name: nginx-container
      image: nginx

kubectl create -f pod-definition.yml

commands

Replica Set

Replica set ensures that a specified number of pods run on node. It automatically brings up a new pod when the existing one fail.

template

rs-definition.yml

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: myapp-rs
  labels:
    app: myapp
    type: frontend
spec:
  replicas: 3
  selector:
    matchLabels:
      type: frontend
  template:
    [POD-TEMPLATE]

selectors is the way for ReplicaSet to know what pods to monitor.

commands

Deployment

A Deployment provides declarative updates for Pods and ReplicaSets. It creates replicaset under an object Deployment

template

deployment-definition.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-rs
  labels:
    app: myapp
    type: frontend
spec:
  replicas: 3
  selector:
    matchLabels:
      type: frontend
  template:
    [POD-TEMPLATE]

selectors is the way for ReplicaSet to know what pods to monitor.

commands

Namespace

Namespaces provide a scope for names. Names of resources need to be unique within a namespace, but not across namespaces. Namespaces cannot be nested inside one another and each Kubernetes resource can only be in one namespace.

template

namespace-definition.yml

apiVersion: v1
kind: Namespace
metadata:
  name: dev

commands

Useful Imperative Commands