iT邦幫忙

2021 iThome 鐵人賽

DAY 2
0
DevOps

玩耍開源k8s30天系列 第 2

day2 : k8s建置(上)

基於現在kubernetes的建置實在太過容易,有kind、k3d、minikube、microk8s等等...,甚至只想佈署服務也可以使用GKE、EKS、AKS這種雲端k8s環境,所以我這邊在環境的選擇上就使用最貼近生產環境可能的配置來進行說明。

做為一套要提供服務的k8s環境,我準備了6台主機os則是用centos 7,一台haproxy作為control plane的load balance,三台control plane控管k8s集群的資源配置管理,兩台computer做為服務運行的node:環境中初次建置的話還需要一台harbor作為image管理使用,為進行自動化以及可延伸為gitops的機能,需要再一台control server和可選的git server作為gitops的管理。

https://ithelp.ithome.com.tw/upload/images/20210902/20139661MFkh3581DO.png

開始建置前首先粗略了解一下,什麼是 terraform什麼是ansible

  • terraform : 配合各種provider的module實現Infrastructure as Code,我認為terraform在雲平台服務廠商上的運用做得非常優秀。
  • ansible : 配合各種ansible module對受管控的主機進行設定,ansible多樣化的module讓操作自由度極高。
    兩者各有優缺,以gcp的infra層面管控我會認為terraform是優於ansible的,但是在長遠的管理角度,使用ansible並搭配inventory做大量控管及調整設定會更為優異,所以我會兩者兼用。

開始配置

在control center這台主機上安裝管理會使用到的套件,我會一開始裝好terraform、ansible、kubectl、docker、krew、kubectl-tree、helm、argoctl、argo rollouts。

安裝(為方便起見我使用root操作)
terraform and ansible

yum install -y yum-utils epel-release
yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
yum install -y terraform ansible

我個人使用的版本是
ansible-2.9.23-1.el7.noarch
terraform-1.0.3-1.x86_64

kubectl

#latest
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
#special version
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.19.11/bin/linux/amd64/kubectl

cp kubectl /usr/local/bin/
chmod 755 /usr/local/bin/kubectl

docker

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce -y
systemctl start docker
systemctl enable docker

krew and kubectl-tree

curl -fsSLO https://github.com/kubernetes-sigs/krew/releases/download/v0.4.1/krew.tar.gz
tar zxvf krew.tar.gz
./krew-linux_amd64 install krew
export PATH="${PATH}:${HOME}/.krew/bin”
echo 'export PATH="${PATH}:${HOME}/.krew/bin”' >> /etc/profile
kubectl krew install tree

helm

curl -fsSLO https://get.helm.sh/helm-v3.6.3-linux-amd64.tar.gz
tar zxvf helm-v3.6.3-linux-amd64.tar.gz
cp ./linux-amd64/helm /usr/local/bin/

argocd and argo rollouts

curl -sSL -o /usr/local/bin/argocd https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64
chmod 755 /usr/local/bin/argocd
curl -LO https://github.com/argoproj/argo-rollouts/releases/latest/download/kubectl-argo-rollouts-darwin-amd64
mv ./kubectl-argo-rollouts-darwin-amd64 /usr/local/bin/kubectl-argo-rollouts
chmod 755 /usr/local/bin/kubectl-argo-rollouts

工欲善其事,必先利其器
這邊安裝好了各種工具,明天開始將會利用這些工具讓k8s輕鬆的佈建及管理。


上一篇
day1 : 介紹與期望
下一篇
day3 : k8s建置(中)
系列文
玩耍開源k8s30天31
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言