Skip to content

Kubernetes Controllers

Syed Sayem edited this page Jan 5, 2020 · 3 revisions

Table of contents

 

top

 

ReplicaSet

  1. Lets deploy some pod with replication controller using yml file

Create a rs-definition.yml file

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: myapp-replicaset
  labels:
    app: myapp
    type: front-end
spec:
  template:
    metadata:
      name: myapp-pod
      labels:
        app: myapp
        type: front-end
    spec:
      containers:
        - name: nginx-controller
          image: nginx
  replicas: 3
  selector:
    matchLabels:
      type: front-end

Deploy using following command

kubectl create -f rs-definition.yml
  1. Get list of replication controller
kubectl get replicationset
  1. Get list of Pods
kuberctl get pods
  1. You can increase the number of pods by updating the yml definition file then running:
kubectl replace -f rs-definition.yml
  1. You can also increase the number of pods by using scale command:
kubectl scale -replicas=6 -f rs-definition.yml
  1. Delete replication set using:
kubectl delete replication myapp-rs

 

top

 

Deployments

A Deployment provides declarative updates for Pods and ReplicaSets.

You describe a desired state in a Deployment, and the Deployment Controller changes the actual state to the desired state at a controlled rate. You can define Deployments to create new ReplicaSets, or to remove existing Deployments and adopt all their resources with new Deployments.

Create a deployment-definition.yml file

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      name: myapp-pod
      labels:
        app: myapp
    spec:
      containers:
      - name: myapp-container-pod
        image: nginx
  1. Lets deploy some pod with deployment using yml file
kubectl create -f deployment-definition.yml
  1. Get list of replication controller
kubectl get deployments
  1. Get list of Pods
kuberctl get pods

 

top

 

StatefulSets

 

top

 

DaemonSet

 

top

 

Job

 

top