Skip to content

2.1 First deploy notes

Microservices

What are Microservics?

they are small autonomous services that work togather.

When to use Microservices?

  • Q: What Microservices is going ot give you?
    • More options to sclae up applications.
    • Zero-downtime independant deployability.
    • Limit the "blast radius" of failure.
    • Isolation of processing around data.
  • "Microservices buy you options."
  • Microservices help you reduce the impact of each service release.
  • As the team size increases it gets hard to coordinate a deployment in Monolith architectures.

When not to use Microservices?

  • Using it for the sake of using new technology.
  • Microservices should not be the default option.
  • You still have the option of breaking a Monolith application into modules instead of Microservices.

Kubernetes

What is Kubernetes?

Kubernetes (k8s) is an open-source system for automating the deployment, scaling, and management of containerized applications. It groups containers that make up an application into logical units for easy management and discovery.

Kubernetes uses labels as "nametags" to identify things including containers.

Pod: runnable unit of work -> Contains one container or multiple tightly coupled containers.

Replication controller: manages a number of pods, it has a pod template that can be replicated any number of times.

Service: Tells the container what other services does the application provide.

Volumes: location where containers can access and store information (multiple storage backends available).

Namespace: grouping mechanism that separates all of the above from each other for isolation.

What is a clutster

a group of machines (nodes) that work togather. the number of nodes can range from 1 to 5000 nodes.

server nodes: nodes that have access to control-plane. agent nodes: nodes that don't have access to control-plane.

craeting a cluster:

$ k3d cluster create -a 2

we can access the config using this command:

$ k3d kubconfig get k3s-default

kubectl is the cli tool that we will use to interact with the clusters we have.

stopping and starting clusters:

$ k3d cluster stop
$ k3d cluster start

$ k3d cluster delete is used to delete a cluster.

to deploy any application we need to create a deployment object with the image of our app.

$ kubctl create deployment hashgenerator-dep --image=<IMAGE_TAG>

Pods can be thought of as container of containers.

to search for information about some resource use this command:

$ kubectl explain RESOURCE

For local docker containers that are not present in remote registries use these commands to get them ready in your deployment:

Import the locally built image:

$ k3d image import <IMAGE_TAG>

Set the image for the deployment:

$ kubectl set image deployment.apps/<DEPLOYMENT_NAME> <CONTAINER_NAME_IN_CLUSTER> =<IMAGE_TAG>

Patch the deployment to allow pulling of local images from local registry:

$ kubectl patch deployment <DEPLOYMENT_NAME> -p '{"spec":{"template":{"spec":{"containers":[{"name":"<CONTAINER_NAME>","imagePullPolicy":"IfNotPresent"}]}}}}'

Declarative approach

Now instead of using command after command, we will make use of yaml files to setup our deployments in better ways.

one example is manifests/deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hashgenerator-dep
spec:
  replicas: 1
  selector:
    matchLabels:
      app: hashgenerator
  template:
    metadata:
      labels:
        app: hashgenerator
    spec:
      containers:
        - name: hashgenerator
          image: jakousa/dwk-app1:b7fc18de2376da80ff0cfc72cf581a9f94d10e64

To apply this deployment we use the apply command:

$ kubectl apply -f manifests/deployment.yaml

now this is all we need to do for a new version of our app:

$ docker build -t <image>:<new_tag>
$ docker push <image>:<new_tag>

then update the tag in the yaml file and run:

$ kubectl apply -f manifests/deployment.yaml