Contents

Kubernetes Getting Started

The basic you need to know when starting with Kubernetes.

Kubernetes provides a form of orchestration for your containers.

Assumptions

A Knowloedge of containers.

Through The History

Kubernetes is a open source code, that was created in 2014 by Google, using Golang. Now it’s maintained by Cloud Native Computing Foundation.

There is a paper of Google from 2015, talking about Google using Borg and Kubernetes. https://research.google/pubs/pub43438/

Another name to Kubernetes is K8S

K ubernete s

Kubernetes Component Architecture

/posts/kubernetes-getting-started/components-of-kubernetes.svg
Components of Kubernetes

Interesting to Know

Kubernetes support more container runtimes than just Docker

Container Runtime Interface (CRI)

  • CRI-O
  • Docker
  • containerd
  • Podman

Kubernetes Objects

There are some Kubernetes objects that you can create via yaml on your cluster.

Namespaces

These objects are a virtual separation of the deployments, services, and another objects on your cluster.

Ingress

Exposes HTTP and HTTPS to services on cluster.

Service

Provides access to your cluster. It can be ClusterIP, NodePort and LoadBalancer.

Service registry are based on DNS, so it creates a DNS for each service running.

Pod

Retains one or more containers

Deployment

It controls how Kubernetes will create pods, in terms of versions, enabling rollout and rollback, scalling, etc.

StatefulSet

Manage pods like Deployment, but with state of volumes.

ReplicaSet

It keeps the desired pods running

HorizontalAutoScaler

It scales the pods based on CPU and memory

PersistentVolume

Volume that maps volume on pod externally

DaemonSet

It makes all nodes, or some of them, run a particular pod

Job

Some command line script or similar

CronJob

It creates Job and schedules it

Hands on

apiVersion: v1
kind: Service
metadata:
  name: my-nginx-svc
  labels:
    app: nginx
spec:
  type: NodePort
  ports:
  - port: 80
    targetPort: 80
    nodePort: 30000
  selector:
    app: nginx
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginxdemos/hello:latest
        ports:
        - containerPort: 80

kubectl is the command line tool that we use to send the commands

Get all namespaces

kubectl get namespace

And, an alias to namespace here on K8S is ns, so you achieve the same thing using this other command below

kubectl get ns

Getting HorizontalAutoScaler

kubectl get horizontalpodautoscaler

And again, there is an alias, it’s hpa

Get pods within the namespace

kubectl -n <namespace> get pod

Scaling deployment horizontally

kubectl -n <namespace> scale --replicas=<desired_pods> deployment <deployment_name>

Get services

kubectl -n <namespace> get service

The alias is svc

See the logs

kubectl -n <namespace> logs pods/<running_pod>

See the logs in real time (“continuous tail”)

kubectl -n <namespace> logs -f pods/<running_pod>

You can also see the log from all the pods, filtering by label, like this

kubectl -n <namespace> logs -l app=<my_app_label>

Enter running pod

kubectl -n <namespace> exec --stdin --tty <running_pod> -- /bin/bash

To exit the pod, just type

exit

Deleting things

You can delete the pod using

kubectl -n <namespace> delete pod <running_pod>

Or even delete a deployment, using

kubectl -n <namespace> delete deployment <some_deployment>

Cluster Monitoring with Istio and Kiali

Downloading istioctl

curl -L https://istio.io/downloadIstio | sh -
cd istio-1.13.0
export PATH=$PWD/bin:$PATH

Installing

istioctl install --set profile=demo -y

Istio uses Envoy as sidecars

Injecting Envoy sidecar

kubectl label namespace default istio-injection=enabled

Result

/posts/kubernetes-getting-started/kiali-example2.png
Kiali running

References