Containers - ji-it/CloudTides GitHub Wiki

Containers let several processes to share the same kernel and some of the packages and commands without knowing the existence of each other.

About etcd

With etcd we can build a cluster. As for the installation of etcd, we can refer to https://ywnz.com/linuxyffq/2262.html

Installation

$ sudo apt -y install wget
$ wget https://github.com/etcd-io/etcd/releases/download/v3.3.10/etcd-v3.3.10-linux-amd64.tar.gz
$ tar xvf etcd-v3.3.10-linux-amd64.tar.gz
$ cd etcd-v3.3.10-linux-amd64
$ sudo mv etcd etcdctl /usr/local/bin
$ sudo mkdir -p /var/lib/etcd/
$ sudo mkdir /etc/etcd
$ sudo groupadd --system etcd
$ sudo useradd -s /sbin/nologin --system -g etcd etcd
$ sudo chown -R etcd:etcd /var/lib/etcd/

Configuration & Starting etcd

Start a systemmd file

$ sudo vim /etc/systemd/system/etcd.service

Use vim to add the following message into the file

[Unit]
Description=etcd key-value store
Documentation=https://github.com/etcd-io/etcd
After=network.target
[Service]
User=etcd
Type=notify
Environment=ETCD_DATA_DIR=/var/lib/etcd
Environment=ETCD_NAME=%m
ExecStart=/usr/local/bin/etcd
Restart=always
RestartSec=10s
LimitNOFILE=40000
[Install]
WantedBy=multi-user.target

Start the etcd

$ sudo systemctl  daemon-reload
$ sudo systemctl  start etcd.service
$ ss -tunelp | grep 2379
$ etcdctl member list

Build a docker image

docker

Install docker on Ubuntu Linux

Add the html-related packages and certificates

$ sudo apt-get update

$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

Add the GPG of the source

$ curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

Add the Docker source

$ sudo add-apt-repository \
    "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu \
    $(lsb_release -cs) \
    stable"

Here, stable'' can be changed into test'' or ``nightly'' if needed.

Install Docker-CE

$ sudo apt-get update
$ sudo apt-get install docker-ce

Start Docker-CE

$ sudo systemctl enable docker
$ sudo systemctl start docker

Set a new user group

"sudo" is already added in the group, and we can add "ve450" in the group by:

$ sudo usermod -aG docker ve450

Test for the installation

We need to exit from our system and return to it to test whether the docker-CE runs well. We need to refer to the following command:

$ docker run hello-world

Get an image from other resources like Docker Hub

$ docker pull [option] [Docker Registry address[:port]/]repository[:tag]

The default repository address is Docker Hub. For example, we can test:
$ docker pull ubuntu:18.04

Run the image

$ docker run -it --rm \
    ubuntu:18.04 \
    bash

The command starts an interactive shell under the image ubuntu:18.04. Here, we can use the command cat /etc/os-release to check the properties of our image which is running. To exit the container, type exit.

List the existing images

$ docker image ls

Delete the existing images

$ docker image rm [options] <image1> [<image2> ...]

Use Dockerfile to build an image

New a file and name it Dockerfile

Use mynginx as an example:

$ mkdir mynginx
$ cd mynginx
$ touch Dockerfile

Find a base of our docker image

After opening Dockerfile, we can revise it by adding lines. Here we use the existing image nginx as an example:

FROM nginx

Build new layers for the image

We can treat the file as a shell when we use the command RUN. For example:

RUN apt-get update

However, if you want to avoid adding two much layers (here, one RUN command means one new layer), you can use && to avoid building new layers over and over again. Like:

FROM debian:stretch

RUN buildDeps='gcc libc6-dev make wget' \
    && apt-get update \
    && apt-get install -y $buildDeps \
    && wget -O redis.tar.gz "http://download.redis.io/releases/redis-5.0.3.tar.gz" \
    && ....

Make use of the revised Dockerfile

In the documentary where the Dockerfile is newed, we use the command

$ docker build [option] <context path/URL/-> .

Set up a K8S cluster

About Kubernetes

Kubernetes can assign the containers that are submitted by users to one of its nodes. It has a structure like

k8s

Method to deal with the Time Exceeds issue

Since we need to use Kubernetes in mainland China and the gcr.io is blocked, we can make use of https://dockerhub.azk8s.cn, a docker hub that is accessible in China.

We use vim to add the following json text in /etc/docker/daemon.json:

{
  "registry-mirrors": [
    "https://dockerhub.azk8s.cn",
    "https://reg-mirror.qiniu.com"
  ]
}

Then we restart the docker:

$ sudo systemctl daemon-reload
$ sudo systemctl restart docker

To check whether the configuration process succeeds, we use $ docker info. If the following texts appear, the process succeeds.

Registry Mirrors:
 https://dockerhub.azk8s.cn/

To use the images, we replace the normal gcd.io with gcr.azk8s.cn.

Installation of Kubernetes

Here, all gcr.io have been replaced into gcr.azk8s.cn. Reference: https://blog.inkubate.io/deploy-kubernetes-1-9-from-scratch-on-vmware-vsphere/

⚠️ **GitHub.com Fallback** ⚠️