Posts

Showing posts from June, 2020

What happens after restart

I have restarted my computer. kubectl cluster-info To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'. The connection to the server 192.168.1.29:6443 was refused - did you specify the right host or port? k8s@PL005596:/home/mawk$ docker ps CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES It seems that nothing is running after the restart. service kubelet status ● kubelet.service - kubelet: The Kubernetes Node Agent    Loaded: loaded (/lib/systemd/system/kubelet.service; enabled; vendor preset: enabled)   Drop-In: /e...

Kubernetes cluster

To run anything with kubernetes we need to define a configuration for our cluster first. Easy way is to use minikube. We won't use that. There are at least 3 executables you would use: kubelet - an application that runs on every node allowing remote interaction kubeadm kubectl - with it you can control the cluster (on local or remote machines), ex. on your computer which might be NOT a part of cluster... in our case it would connect to local host So go to https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/ then execute # systemctl restart kubelet # we are trying to restart kubelet... I already had this working # journalctl -xe  # wait... something is not right let's check the logs # swapoff -a  # it was refusing to run on my system as I had swap enabled thus I'm disabling the swap # service kubelet status  #checking kubelet status... and it is still not starting... in fact restarting all the time # service kubelet stop  # no need t...

Lets try to run our docker image with k8s...

Kubernetes should run, monitor, restart and scale our application "service1". cd ~/service1 vim service1-deployment.yaml # See https://kubernetes.io/docs/concepts/workloads/controllers/deployment/ for example content used here cd ~/service1 docker build --tag easyk8s-service1 . -f Dockerfile Sending build context to Docker daemon  6.144kB Step 1/4 : FROM python:3  ---> 659f826fabf4 Step 2/4 : ADD service.py /  ---> ccd341c35691 Step 3/4 : COPY www /  ---> 605b15b64ab0 Step 4/4 : CMD ["python", "service.py"]  ---> Running in a9aaa32e5fdc Removing intermediate container a9aaa32e5fdc  ---> 232da1056511 Successfully built 232da1056511 Successfully tagged easyk8s-service1:latest vim service1-deployment.yaml apiVersion: apps/v1 kind: Deployment metadata:   name: service1-deployment   labels:     app: service1 spec:   replicas: 1   selector:     matchLabels:       app: servic...

Let's start with docker...

# Create user for kubernetes # Note that you would need to run as root if going with kvm2 instead of docker sudo su adduser k8s # enter password twice and confirm to create the user # Download kubectl su k8s mkdir bin && cd bin curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl chmod +x kubectl # Check that you have docker docker ps # If got 'command not found' you should install docker # Let's assume we are running debian based linux (ex. ubuntu): sudo su apt install docker -y usermod k8s -G sudo,docker # sudo allows k8s user to become the root, docker allows us to control docker from k8s user # Let's log-out and log-in to k8s account # It is not windows - no need to restart, just press ctrl+d on every session with k8s logged and log-in again # Let's check docker if it is working... in my case there was some problem I had to solve docker ...

Lets create a cluster - foreword

We would be running a full kubernetes (multi-node support) on a single node only (this is more complex but lets us learn more). Starting with something "simple" going onto full application. On local computer and using docker. My computer has ubuntu installed. Several reasons why you should NOT be using windows: It is large and consumes a lot of resources It does not scale It does many things without you knowing You cannot check its sources It sends a lot of data to advertisement servers It installs and deletes applications without asking you for permission (ex. soda saga crap) It installs updates without asking and force you to install them When updating it would restart When <whatever> it would restart You could block the updates... almost and with a lot of effort It is not secure I have a laptop with 32GB eMMC disk (difficult to replace) and 2GB of RAM - it cannot even update on clean system without any apps installed... at the same time linux can easily run on a ver...

Cluster, node, minikube

Out containers are running on some machine (likely a physical server). Such a server is called a node. Our application might require a large ecosystem of microservices - possibly thousands of such physical machines. They all create a cluster of nodes. To learn you often start with a minikube - a single node k8s. This way many things are done for you - but you would skip some important steps and, at some point, you would need to go through full k8s installation. Summary: Cluster of nodes running pods (containers) on them. Minikube is 1-node only cluster with many things already done.

Deployment

To create a pod you would need: an image of operating system (to run inside a container) image should likely include our application instruction describing container creation This (and more) is called a deployment .

Pod, container

Your application probably consists of microservices. Each would be running in its own virtual machine (or physical machine... it doesn't really matter). Suc a virtual machine is our "container" . A container could be rarely a physical machine. Usually it would be a virtual machine on aws, azure, google cloud or our own server. Container is created using some virtualization technology. Some examples are virtualbox, hyperv, vmware, kvm2, docker. My choice is to use docker . For k8s container is a pod . Like a pod of whales (group of whales). But creation of the container might fail - thus one pod could have more than one container under it. Summary: A pod is one (or more) machine (likely virtual) called "container".

Introduction

If you are here, then most likely you would like to start with kubernetes but you do not know where to begin. Like me once. K8s documentation can be found at https://kubernetes.io . K8s is an orchestration tool for your cloud. It means it would create, maintain, kill, restart and do some more things with your cloud computers. Basic commands of kubernetes are kubectl and kubeadm. Most things are configured using .yaml or .json files. Difficult things: - graphical management is possible but unstable, with issues, not everything can be done there - text-only command line is something you must get used to - security is quite complex - multiple machines communication won't always work - causing a lot of issues

The goal

My goal is to present Kubernetes (also known as k8s for short) in a short, easy and least painful way possible.