Kubernetes
1. Kubernetes Architecture
        Â
2. Basic Objects
If In need, can stateful Volumes, which will be persistent, even after the deployment got deleted.- Namespaces
Namespaces are abstraction or sandboxed environmentsNames of resources need to be unique within a namespace, but not across namespaces.
Namespaces can not be nested inside one another and each Kubernetes resource can only be in one namespace
3. Types of Service
1.NodePort
2.LoadBalancer
3.Ingress
Code Example for a deployment
Telemetry Deployment Code
--- apiVersion: apps/v1 kind: Deployment metadata: name: telemetry namespace: exp spec: replicas: 1 selector: matchLabels: app: telemetry template: metadata: labels: app: telemetry spec: imagePullSecrets: - name: sunbird containers: - name: telemetry image: ntphub.azurecr.io/telemetry-service:release-2.1.1_RC1 imagePullPolicy: Always resources: requests: cpu: 100m memory: 200Mi ports: - containerPort: 5000 envFrom: - configMapRef: name: telemetry-config --- apiVersion: v1 kind: Service metadata: name: telemetry-service namespace: exp spec: ports: - port: 5000 targetPort: 5000 selector: app: telemetry
strategy: Â Â Â rollingUpdate: Â Â Â Â Â maxSurge: 1 Â Â Â Â Â maxUnavailable: 0 Â Â Â type: RollingUpdate
 2. The following snippet should be part of the deployment yaml file. This allows us to configure the endpoints that K8s can use to detect that a new container is ready for use.
    livenessProbe:               httpGet:            path: /service/live           port: 8080            scheme: HTTP        initialDelaySeconds: 15          periodSeconds: 2          successThreshold: 1          timeoutSeconds: 3        readinessProbe:          httpGet:            path: /service/ready            port: 8080            scheme: HTTP          initialDelaySeconds: 15            periodSeconds: 2          successThreshold: 1          timeoutSeconds: 3
 3. The application should handle SIGTERM requests and delay shutdown (Thread.sleep or JS equivalent) for some duration - ideally 30 seconds. This gives enough time for the container (being purged) to complete all requests    that it was already processing. The container would stop getting new requests once the SIGTERM is sent to it.
--- apiVersion: autoscaling/v1 kind: HorizontalPodAutoscaler metadata: name: telemetry spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: content minReplicas: 1 maxReplicas: 10 targetCPUUtilizationPercentage: 70