Kubernetes

POD

Description

C’est la plus petite unité que l’on peut déployer dans Kubernetes.
Le Pod contient le/les containers.

CLI

kubectl run myapp-pod --image=nginx [--port=80]

YAML

pod-definition.yml

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

Application

kubectl create -f pod-definition.yml

Replication Controller

Description

C’est le prédécesseur du ReplicaSet, il s’assure que le nombre de replica de pod dans le cluster soit respecté.
Son abréviation est rc dans les commandes.

YAML

replicationcontroller-def.yml

apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx
spec:
  replicas: 3
  selector:
    app: nginx
  template:
    metadata:
      name: nginx
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx

Note: c’est l’ajout dans la section spec/template (du ReplicationController) de la section metadata et spec du pod.

ReplicationController_Pod_yaml

Application

kubectl create -f replicationcontroller-def.yml

ReplicaSet

Description

Un ReplicaSet maintient le nombre de replica de pod dans le cluster. Son abréviation est rs.

YAML

replicaset-def.yml

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      name: nginx
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        imahe: nginx

Note: c’est l’ajout dans la section spec/template (du ReplicaSet) de la section metadata et spec du pod.
ReplicaSet_Pod_yaml

Application

kubectl create -f replicaset-def.yml

Deployment

YAML

deployment-def.yml

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

Application

kubectl create -f deployment-def.yml

Namespace

Description

Séparer les objets dans des namespaces dédiés.

CLI

kubectl create namespace <my_namespace>

YAML

namespace-def.yml

apiVersion: v1
kind: Namespace
metadata:
  name: my_namespace

Application

kubectl create -f namespace-def.yml

Resource Quota

YAML

resourcequota-def.yml

apiVersion: v1
kind: ResourceQuota
metadata:
  name: my_resourcequota
  namespace: dev
spec:
  hard:
    pods: "10"
    requests.cpu: "4"
    requests.memory: 5Gi
    limits.cpu: "10"
    limits.memory: 10Gi

Application

kubectl create -f resourcequota-def.yml