DevOps Classroom notes 20/Feb/2025

Annotations in k8s

Deployments

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
  annotations:
    kubernetes.io/change-cause: "Initial deployment"
spec:
  replicas: 4
  selector:
    matchLabels:
      app: nginx
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: nginx:1.14.2
          ports:
          - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
  type: NodePort


  • Then we have changed to
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
  annotations:
    kubernetes.io/change-cause: "moved to apache"
spec:
  replicas: 4
  selector:
    matchLabels:
      app: nginx
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: httpd:latest
          ports:
          - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
  type: NodePort


  • Use kubectl rollout command to view the deployment status

Daemonsets

  • Refer Here for official docs
  • Daemonsets allocate pods per node or node selection
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: fluentd-elasticsearch
  namespace: kube-system
  labels:
    k8s-app: fluentd-logging
spec:
  selector:
    matchLabels:
      name: fluentd-elasticsearch
  template:
    metadata:
      labels:
        name: fluentd-elasticsearch
    spec:
      containers:
      - name: agent
        image: alpine
        command:
          - sleep
          - 1d

Namespaces

  • Namespace help in creating segregations i.e. like folders we can have some workloads distributed across these logical clusters Refer Here
  • All k8s resources cannot be part of namespace
  • Generally its a good idea to create namespaces for applications which require isolations
  • We can allocate Quotas to the namespace
  • Lets create a namespace and deploy a sample application
---
apiVersion: v1
kind: Namespace
metadata:
  name: dev
  labels:
    name: web

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  namespace: dev
  labels:
    app: nginx
  annotations:
    kubernetes.io/change-cause: "Initial deployment"
spec:
  replicas: 4
  selector:
    matchLabels:
      app: nginx
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: nginx:1.14.2
          ports:
          - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
  namespace: dev
spec:
  selector:
    app: nginx
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
  type: NodePort

Kubernetes Administrative Activites

  • This includes
    • backup,
    • role based access control
    • upgrades to kubernetes
    • Pod scheduling

Pod Scheduling

Note

  • Commands used in class
kubectl get nodes
cd specs/
kubectl apply -f deploy.yaml 
kubectl get all
kubectl rollout status deployment nginx-deployment 
kubectl rollout status history nginx-deployment 
kubectl rollout history deployment nginx-deployment 
kubectl delete -f deploy.yaml 
kubectl apply -f deploy.yaml 
kubectl rollout history deployment nginx-deployment 
kubectl get svc
kubectl apply -f deploy.yaml 
kubectl rollout history deployment nginx-deployment 
kubectl rollout undo deployment  nginx-deployment
kubectl delete -f deploy.yaml kubectl get nodes
kubectl apply -f daemonset.yaml 
kubectl get ds
kubectl get all
kubectl delete -f daemonset.yaml 
kubectl apply -f daemonset.yaml 
kubectl get all
kubectl apply -f daemonset.yaml 
kubectl get all
kubectl rollout history daemonset fluentd-elasticsearch 
kubectl get namespace
kubectl create ns test
kubectl get namespace
kubectl api-resources 
ls
vi otherdeploy.yaml
kubectl apply -f otherdeploy.yaml 
kubectl get deploy
kubectl get deploy -n dev
kubectl config set-context --current --namespace=dev
kubectl get po
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%%