Skip to content
LinkedIn GitHub X

Blog

Kubernetes 101: Introduction

Kubernetes Cover

Hi, welcome to the wonderful world of DevOps. This is a post I wrote while learning Kubernetes. So, let’s start the journey!😎.

πŸ“„ What is Kubernetes?

Since release by Google in 2014, Kubernetes has become a very popular technology in modern cloud infrastructure. It is a useful open-source orchestrator for containerizing applications.

Kubernetes everywhere meme

The name Kubernetes comes from the Greek, meaning β€œnavigator” or β€œpilot”. As such, Kubernetes is expected to become an open-source platform that can be used for application workload management, as well as providing declarative configuration and automation. Now, with widely available services, support and tools, Kubernetes has a large and rapidly growing ecosystem.

Based on its experience over the last decade, and with the best ideas coming from the community, Google created Kubernetes, see Large-scale cluster management at Google with Borg for more.

By the way, Kubernetes is not a monolithic system, but rather a building block and pluggable system that is needed to build a platform that developers want, while still prioritizing the concept of flexibility.

⚑ Kubernetes Features

There are many features of Kubernetes:

- Service discovery and load balancing, means Kubernetes can expose containers using their DNS or IP. Kubernetes can also perform load balancing and distribute traffic within a system.

- Storage orchestration, Kubernetes automatically installs storage systems, either on-premises or cloud services.

- Deployment and automatic rollback, Kubernetes will change the current state to the user’s desired state at a controlled rate. For example, Kubernetes will automatically create a new container, delete the old container, and adopt its resources into the new container.

- Automatic Packing, Kubernetes is very efficient in the allocation of memory (RAM) and CPU usage for each container.

- Recovery, Kubernetes can restart failed containers, replace containers, and shut down containers that do not respond and do not provide services to users.

- Managing secrets and configurations, Kubernetes stores and manages sensitive information, such as passwords, OAuth tokens, and SSH keys, so this information can be updated without creating container images and exposing existing secrets.

- Providing PaaS services, Kubernetes provides features such as deployment, scaling, load balancing, logging, and monitoring, although Kubernetes runs at the container level rather than the hardware level.

😌 The following features are not available!?

Kubernetes meme

There are some features not included or provided by Kubernetes, for example:

- Kubernetes aims to support all variations of workloads (including stateless or stateful, and data processing), so as long as the application is running on containers, there is no limit to the applications that can be supported.

- Kubernetes does not provide a CI/CD workflow mechanism.

- Kubernetes does not provide application-level services such as middleware (e.g. message buses), data processing frameworks (e.g. Spark), databases (e.g. MySQL), caches, or cluster storage systems (e.g. Ceph) as an integrated service. But all of these components can run on Kubernetes.

- Kubernetes does not provide or require a configuration language like Jsonnet, as it provides a declarative API that can be used with different types of declarative specifications.

- Kubernetes does not provide or adapt a configuration for the machine’s maintenance, management, or self-healing to any particular specification.

Reference:

- KUBERNETES UNTUK PEMULA. https://github.com/ngoprek-kubernetes/buku-kubernetes-pemula.

Thank you for reading this post.πŸ˜€

Install Docker using Ansible

Setup

First, you need to install Ansible. Just follow this link to install Ansible on your operating system installation guide.

After installation, create new directory called ansible-docker.

Terminal window
$ mkdir ansible-docker && cd ansible-docker

Create a new file called ansible.cfg as the Ansible configuration setting and then define the inventory file.

[defaults]
inventory = hosts
host_key_checking = True
deprecation_warnings = False
collections = ansible.posix, community.general

Then create a new file called hosts, where the name is defined on ansible.cfg.

Terminal window
[example-server]
0.0.0.0 ansible_user=root

NB: Don’t forget to change the IP Address and host name.

After setup the Ansible configuration setting & inventory file, let’s create a YAML file called playbook.yml

---
- name: Setup Docker on Ubuntu Server 22.04
hosts: all
become: true
remote_user: root
roles:
- config
- docker

Then create roles directory:

  • Config, On this directory I will create a directory called tasks. After that, I should create yaml file called main.yml to run update, upgrade & install many dependencies.
---
- name: Update&Upgrade
ansible.builtin.apt:
name: aptitude
state: present
update_cache: true
- name: Install dependencies
ansible.builtin.apt:
name:
- net-tools
- apt-transport-https
- ca-certificates
- curl
- software-properties-common
- python3-pip
- virtualenv
- python3-setuptools
- gnupg-agent
- autoconf
- dpkg-dev
- file
- g++
- gcc
- libc-dev
- make
- pkg-config
- re2c
- wget
state: present
update_cache: true
  • Docker, On this directory create 2 directories called tasks & templates.

On tasks directory create new file called main.yml. This file contains Docker installation, Docker Compose installation & private registry setup.

---
- name: Add Docker GPG apt Key
ansible.builtin.apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present
- name: Add repository into sources list
ansible.builtin.apt_repository:
repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_lsb.codename }} stable
state: present
filename: docker
- name: Install Docker 23.0.1-1
ansible.builtin.apt:
name:
- docker-ce=5:23.0.1-1~ubuntu.22.04~jammy
- docker-ce-cli=5:23.0.1-1~ubuntu.22.04~jammy
- containerd.io
state: present
update_cache: true
- name: Setup docker user
ansible.builtin.user:
name: docker
groups: "docker"
append: true
sudo_user: yes
- name: Install Docker module for Python
ansible.builtin.pip:
name: docker
- name: Install Docker-Compose&Set Permission
ansible.builtin.get_url:
url: https://github.com/docker/compose/releases/download/1.29.2/docker-compose-Linux-x86_64
dest: /usr/local/bin/docker-compose
mode: '755'
- name: Create Docker-Compose symlink
ansible.builtin.command:
cmd: ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
creates: /usr/bin/docker-compose
- name: Add private registry
ansible.builtin.template:
src: daemon.j2
dest: /etc/docker/daemon.json
mode: preserve
- name: Restart Docker
ansible.builtin.service:
name: docker
state: restarted
enabled: true

In the template, create a template file using a jinja file named daemon.j2. This file contains configuration for private registry settings (optional).

{
"insecure-registries" : ["http://0.0.0.0:5000"]
}

NB: Field the IP using your remote server private IP

After all setup, Your project directory should look like this:

Terminal window
$ tree
.
β”œβ”€β”€ ansible.cfg
β”œβ”€β”€ config
β”‚ └── tasks
β”‚ └── main.yml
β”œβ”€β”€ docker
β”‚ β”œβ”€β”€ tasks
β”‚ β”‚ └── main.yml
β”‚ └── templates
β”‚ └── daemon.j2
β”œβ”€β”€ hosts
└── playbook.yml

Test & Run

Okay, now test Your playbook.yml file using this command.

Terminal window
$ ansible-playbook --syntax-check playbook.yml

If You don’t have any errors, run the playbook using this command.

Terminal window
$ ansible-playbook -i hosts playbook.yml

Wait until finish.

Terminal window
____________________________________________
< PLAY [Setup Docker on Ubuntu Server 22.04] >
--------------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
________________________
< TASK [Gathering Facts] >
------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||

Conclusion

In this post, I just show you how to install Docker in a specific version using Ansible Playbook when you have one or more servers.

Thank You for reading this post, If You have suggestions or questions please leave them below. Thanks

NB: In this case, I just set the user as root. I installed the Docker on Ubuntu Server 22.04. For full code follow this link ansible-docker.