DevOps Classroom notes 11/Feb/2025

Interacting with k8s

  • kubectl works with commands and manifest files
  • Manifest files of k8s are in yaml format

YAML

  • YAML is a file format which represents data
  • YAML is collection of name value pairs
<name1>: <value1>
<name2>: <value2>
..
<namen>: <valuen>
  • name is generally text and value can be any thing which you want to represent
  • Consider you want to reprsent resume, lets figure out name
    • name
    • address
    • contact
    • professional summary
    • skills
    • work experience
    • educational qualificatios
  • The value comes in different forms
    • text
    • number
    • boolean
    • list/array
    • map/object
  • text
qualification: BTech
qualification: 'BTech'
qualification: "BTech"
  • number
percentage: 71.10
age: 24
  • boolean: can have true or false or yes or no as valid values
online: true
online: yes
readytorelocate: false
readytorelocate: no
  • list: this is used to represent plural data
programminglanguages: [ "python", "java" ]
programminglanguages:
  - python
  - java
  • map or object: Here we reprsent data which requires further name value pairs
address:
  flat: 601
  building: nilgiri
  area: ameerpet
  landmark: near metro
  city: hyderabad

skills:
  containers:
    - Docker
    - Kubernetes
  cicd:
    - Github Actions
    - Azure DevOps
    - Jenkins
  programming: python
  • A yaml file will generally have an extension of .yml or .yaml
  • YAML and JSON are formats which were designed to be both machine and human understandable
  • YAML files used for a tool will have its own defined structure (schema)
  • Docker-compose yaml
version: '3.9'
services:
  my-nginx-service:
    container_name: my-website
    image: my-nginx-image:latest
    cpus: 1.5
    mem_limit: 2048m
    ports:
      - "8080:80"
  my-db:
    image: mysql:9
    ports:
      - "3306"
volumes:
  my-vol:
  • k8s sample yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: myapp-replicas
  labels:
    app: myapp
    tier: frontend
spec:
  replicas: 3
  selector:
    matchLabels:
      tier: frontend
    matchExpressions:
      - {key: tier, operator: In, values: [frontend]}
  template:
    metadata:
      labels:
        app: myapp
        tier: frontend
    spec:
      containers:
        - name: nginx
          image: nginx
          ports:
            - containerPort: 80

  • Come up with a yaml format to describe your mobile
model: 
manufacturer:
color:
spec:
  memory:
  storage:
camera:
  selfie:
  main:
os:
apps:
  - youtube
  • To write k8s manifest we need to understand the following
    • apiVersioning
    • types
  • apiVersioining in k8s
    • channels:
      • alpha: it includes term alpha in it
      • beta: it includes term beta in it
      • stable: The version name is vX where X is an integer.
    • Api Groups: Resources are grouped into api Groups
      • core: All the resources in the core group will have group name as core when we write apiVersion: <version> i.e. apiVersion: v1
      • named: this will have apiVersion as <group>/<version> apiVersion: apps/v1
  • K8s manifest mostly have 4 major fields
    • apiVersion: This represents the api version and group
    • kind: This represents the kind of resource
    • metadata: This is metadata for resource which majorly includes names and lablels
    • spec: this is the desired state of the resource
  • Sample pod manifest (incomplete)
apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
spec:

  • Sample Service Manifest (incomplete)
apiVersion: v1
kind: Service
metadata:
  name: nginx-svc
spec: 
  • Sample deployment manifest (incomplete)
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deploy
spec: 
Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a comment

Turn on JavaScript to leave a comment.

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

Please turn AdBlock off
Social Media Icons Powered by Acurax Web Design Company
Exit mobile version
%%footer%%