Skip to content

Instantly share code, notes, and snippets.

@HoKim98
Created February 20, 2021 23:18
Show Gist options
  • Save HoKim98/7121144fabea2707b46c9f43a80578c3 to your computer and use it in GitHub Desktop.
Save HoKim98/7121144fabea2707b46c9f43a80578c3 to your computer and use it in GitHub Desktop.
# SmartX mini

Lab: Clustering

Rook 설치 준비

비어있는 디바이스 혹은 파티션이 최소 하나가 존재해야 한다.

sudo cfdisk /dev/sdX

Kubernetes 설치

sudo swapoff -a
sudo vim /etc/fstab  # swap 기능을 제거한다.

설치 (Ubuntu 20.04)

# (Install Docker CE)
## Set up the repository:
### Install packages to allow apt to use a repository over HTTPS
sudo apt-get update && sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common gnupg2

# Add Docker's official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key --keyring /etc/apt/trusted.gpg.d/docker.gpg add -

# Add the Docker apt repository:
sudo add-apt-repository \
  "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) \
  stable"

# Install Docker CE
sudo apt-get update && sudo apt-get install -y \
  containerd.io=1.2.13-2 \
  docker-ce=5:19.03.11~3-0~ubuntu-$(lsb_release -cs) \
  docker-ce-cli=5:19.03.11~3-0~ubuntu-$(lsb_release -cs)

## Create /etc/docker
sudo mkdir /etc/docker

# Set up the Docker daemon
cat <<EOF | sudo tee /etc/docker/daemon.json
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2"
}
EOF

# Create /etc/systemd/system/docker.service.d
sudo mkdir -p /etc/systemd/system/docker.service.d

# Create /etc/systemd/system/docker.service.d
sudo mkdir -p /etc/systemd/system/docker.service.d

sudo systemctl daemon-reload
sudo systemctl enable docker
sudo systemctl restart docker
sudo systemctl restart docker.socket

# Install kubernetes
sudo apt-get update && sudo apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
http://apt.kubernetes.io/ kubernetes-xenial main
EOF

sudo apt-get install && sudo apt-get install -y kubelet kubeadm kubectl

cgroups 관련 문제가 발생 시

https://kubernetes.io/docs/setup/production-environment/container-runtimes/#docker

재발생 시

sudo systemctl daemon-reload
sudo systemctl restart docker
sudo systemctl restart docker.socket

초기화

sudo kubeadm reset
sudo rm -r /etc/cni/net.d
sudo ipvsadm --clear  # ipvsadm 가 없다면 설치할 것

# Cleanup Rook configuration
sudo rm -rf /var/lib/rook

sudo kubeadm init

rm -r $HOME/.kube
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

# Schedule master node (=control plane node)
kubectl taint nodes --all node-role.kubernetes.io/master-

# kubeadm join 관련 함수는 기억할 것

노드 추가 (노드 참가)

sudo kubeadm reset
sudo rm -r /etc/cni/net.d
sudo ipvsadm --clear  # ipvsadm 가 없다면 설치할 것

# Cleanup Rook configuration
sudo rm -rf /var/lib/rook

# kubeadm join ...

네트워크 정책

cni 관련 문제로 잘 작동되지 않을 땐, kube-flunnel 사용을 권장한다.

kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"

네트워크 정책 점검

watch kubectl get pod -n kube-system

Rook 설치

2020-02-20 현재, ceph:v15 버전에서 싱글 파티션을 인식하지 못하는 문제가 발생했다.

때문에 여기서는 ceph:v14 버전을 사용하는, rook:v1.2 버전을 사용하도록 하겠다.

cd $HOME
git clone --single-branch --branch release-1.2 https://github.com/rook/rook.git
cd $HOME/rook/cluster/examples/kubernetes/ceph
kubectl create -f common.yaml
kubectl create -f operator.yaml

# 선택
kubectl create -f cluster.yaml  # production 용. 3개 nodes가 연결되어야 한다.
kubectl create -f cluster-test.yaml  # dev 용. 1개 node만 연결되어도 좋다.

설치 상태 모니터링

단순 pod 실행환경 점검

rook-ceph-osd pod이 제대로 준비되어야 한다. 여기까지 오는데에 많은 시도가 필요할 것이다...

watch kubectl get pod -n rook-ceph

Toolbox를 이용하는 방법

설치
cd $HOME/rook/cluster/examples/kubernetes/ceph
kubectl create -f toolbox.yaml
kubectl -n rook-ceph rollout status deploy/rook-ceph-tools
실행
kubectl -n rook-ceph exec -it deploy/rook-ceph-tools -- bash

# In the toolbox,
watch ceph status

StorageClass 추가

# 선택
kubectl apply -f csi/rbd/storageclass.yaml  # production
kubectl apply -f csi/rbd/storageclass-test.yaml  # dev

WordPress 설치

kubectl create -f $HOME/rook/cluster/examples/kubernetes/mysql.yaml
kubectl create -f $HOME/rook/cluster/examples/kubernetes/wordpress.yaml

설치 상태 모니터링

watch kubectl get pod

접속

아래의 출력 결과물 URL로 접속한다.

WORDPRESS_IP=$(ip addr | grep "inet " | grep "dynamic" | sed -n -e "s/.*inet \([0-9.]\+\).*/\1/p")
WORDPRESS_PORT=$(kubectl get svc | grep "wordpress " | sed -n -e "s/.*80:\([0-9]\+\).*/\1/p")
echo "http://$WORDPRESS_IP:$WORDPRESS_PORT"

제거

kubectl delete -f $HOME/rook/cluster/examples/kubernetes/mysql.yaml
kubectl delete -f $HOME/rook/cluster/examples/kubernetes/wordpress.yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment