DevOps Classroomnotes 28/Apr/2023

Controllers

  • Controllers in k8s control/maintain state of k8s objects

ReplicaSet

  • Refer Here for ReplicaSet official docs
  • ReplicaSet is controller which maintains count of Pods as Desired State

RS-Activity1 Create 3 nginx pods

  • Refer Here for the nginx rs manifest without selector
  • temporary workaround for adding selectors. Refer Here for the changes added
  • Now apply the manifest
  • Lets change the replica count
  • We can increase (scale out) as well decrease (scale in) the replica count

RS-Activity2 Create 5 Pods with jenkins and alpine in one Pod

  • Refer Here for the manifest
  • Apply the manifest

  • Get events from describe rs
  • Now delete a pod manually

Labels

  • Refer Here for official docs
  • Labels are key value pairs that can be attached as metadata to k8s objects.
  • Labels help in selecting/querying/filtering objects
  • Labels can be selected using

Label Activity 1. Create a nginx pod with label

  • Lets create a nginx pod with label app: nginx
  • Refer Here for the pod spec with labels
  • Lets run some other pods using declartative

  • Selectors

  • Create 5 pods with label app=jenkins
  • Now run the replicaset with 5 replicas
---
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: jenkins-rs
spec:
  minReadySeconds: 5
  replicas: 5
  selector:
    matchLabels:
      app: jenkins
  template:
    metadata:
      name: jenkins
      labels:
        app: jenkins
    spec:
      containers:
        - name: jenkins
          image: jenkins/jenkins:lts-jdk11
          ports:
            - containerPort: 8080
        - name: alpine
          image: alpine:3
          args:
            - sleep
            - 1d

  • Jenkins rs didnt create any pod as there were 5 pods matching label selector. we had deleted one pod which lead to creation of jenkins pod from the template section in above manifest
  • ReplicationController only allows equality based selectors where as ReplicaSet supports set based selectors also
  • Sample
---
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: setbased
  labels:
    purpose: understanding
    concept: setbased
spec:
  minReadySeconds: 2
  replicas: 3
  selector:
    matchExpressions:
      - key: app
        operator: In
        values:
          - nginx
          - web
      - key: env
        operator: NotIn
        values:
          - prod
          - uat
      - key: failing
        operator: DoesNotExist
        values:
  template:
    metadata:
      name: nginx
      labels:
        app: nginx
        env: dev
    spec:
      containers:
        - name: nginx
          image: nginx:1.23
          ports:
            - containerPort: 80

Exercise

  • Write a manifest to create
    • nginx replication controller with 3 pods

Next Steps

  • Service
  • InitContainers
  • Health Probes
  • Managed K8s
Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Customized Social Media Icons from Acurax Digital Marketing Agency

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version
%%footer%%