Install K8s cluster, Rancher, Elasticsearch & Kibana on local (mac)#
K3s + Rancher#
- Prerequisite:
- install brew by https://brew.sh/
- install multipass by
brew cask install multipass
- Makefile:
.PHONY: all
k3s:
multipass launch --name k3s --cpus 4 --mem 4g --disk 20g
## 以下這段是已準備好多個 Node,在各個 Node 執行
#curl -sfL https://get.k3s.io | sh -s - server \
# --write-kubeconfig-mode 644 \
# --datastore-endpoint="mysql://root:123456@tcp(172.16.8.190:3306)/k3sdb"
## 以下這個是創建空的 cluster
multipass exec k3s -- bash -c "curl -sfL https://get.k3s.io | sh -s - --write-kubeconfig-mode 644"
K3S_IP=$(shell multipass info k3s | grep IPv4 | awk '{print $$2}')
cfg:
multipass exec k3s sudo cat /etc/rancher/k3s/k3s.yaml > k3s.yaml
sed -i '' "s/127.0.0.1/${K3S_IP}/" k3s.yaml
multipass exec k3s -- sudo bash -c "sed -i s/127.0.0.1/${K3S_IP}/ /etc/rancher/k3s/k3s.yaml"
export KUBECONFIG=${PWD}/k3s.yaml
@cp /etc/hosts backup_hosts
@echo "${K3S_IP} rancher.localdev" | sudo tee -a /etc/hosts > /dev/null
mnt:
@mkdir shareFolder
@cp ./Makefile ./shareFolder/Makefile
@multipass mount ./shareFolder k3s:./shareFolder
@multipass exec k3s -- bash -c "sudo apt install make"
@multipass exec k3s -- bash -c "cp ./shareFolder/Makefile Makefile"
@multipass exec k3s -- bash -c "make init"
cluster: k3s cfg mnt
init:
###### 安裝 helm 3
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh
###### 安裝 cert-manager
kubectl apply --validate=false -f https://github.com/jetstack/cert-manager/releases/download/v0.15.0/cert-manager.crds.yaml
kubectl create namespace cert-manager
helm repo add jetstack https://charts.jetstack.io
helm repo update
kubectl config view --raw >~/.kube/config
helm install --wait --timeout=30s \
cert-manager jetstack/cert-manager \
--namespace cert-manager \
--version v0.15.0
kubectl rollout status --watch DEPLOYMENT/cert-manager -n cert-manager
###### 安裝 rancher
helm repo add rancher-stable https://releases.rancher.com/server-charts/stable
helm repo update
kubectl create namespace cattle-system
helm install rancher rancher-stable/rancher \
--namespace cattle-system \
--set hostname=rancher.localdev
kubectl -n cattle-system rollout status deploy/rancher
kubectl -n cattle-system get ingresses
del:
multipass stop k3s
multipass delete k3s
multipass purge
@sudo cp -f backup_hosts /etc/hosts
rm -rf backup_hosts
rm -rf ./shareFolder
rm -rf k3s.yaml
Elasticsearch#
- Name: es
- Workload Type (click More options): Stateful set of 1 pod
- Docker Image: elasticsearch:7.6.2
- Port Mapping: nodeport 9200
- Environment Variables: discovery.type = single-node
Kibana#
- Name: kibana
- Docker Image: kibana:7.6.2
- Port Mapping: nodeport 5601
- Environment Variables: ELASTICSEARCH_HOSTS = http://es:9200
Reference#