DevOps Classroomnotes 28/Apr/2023

Controllers

  • Controllers in k8s control/maintain state of k8s objects

Preview

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
    Preview
  • temporary workaround for adding selectors. Refer Here for the changes added
  • Now apply the manifest
    Preview
  • Lets change the replica count
    Preview
  • We can increase (scale out) as well decrease (scale in) the replica count
    Preview

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

  • Refer Here for the manifest
  • Apply the manifest
    Preview
    Preview
  • Get events from describe rs
    Preview
  • Now delete a pod manually
    Preview

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
    Preview
  • Lets run some other pods using declartative
    Preview
    Preview
  • Selectors
    Preview
    Preview
  • Create 5 pods with label app=jenkins
    Preview
  • 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
    Preview
  • 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

Leave a Reply

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

About continuous learner

devops & cloud enthusiastic learner