-
Notifications
You must be signed in to change notification settings - Fork 8
kubernetes
i0gan edited this page Aug 11, 2024
·
3 revisions
正式环境请自行搭建物理集群,本次为了方便教学,k8s集群采用基于docker的kind来进行创建。
需要预先安装 go, docker
k8s学习:
bilibili: https://www.bilibili.com/video/BV1Tg411P7EB/
zhihu: https://zhuanlan.zhihu.com/p/616621837
ref: https://kind.sigs.k8s.io/
设置 go 代理
echo "export GO111MODULE=on" >> ~/.profile
echo "export GOPROXY=https://goproxy.cn" >> ~/.profile
source ~/.profile
设置path
echo "export PATH=$PATH:~/go/bin" >> ~/.profile
source ~/.profile
下载kind
go install sigs.k8s.io/kind@v0.20.0 && kind create cluster
ref: https://kind.sigs.k8s.io/
设置go代理
SETX GO111MODULE on
go env -w GOPROXY=https://goproxy.cn,direct
SETX GOPROXY https://goproxy.cn,direct
下载kind
go install sigs.k8s.io/kind@v0.20.0
增加c:/Users/{user}/go/bin路径到环境变量
kind create cluster
如果拉取不到镜像,可通过国内代理拉取
docker pull m.daocloud.io/docker.io/kindest/node:v1.27.3
kind create cluster --name kind --image m.daocloud.io/docker.io/kindest/node:v1.27.3
ref: https://kubernetes.io/docs/tasks/tools/install-kubectl-windows/
curl.exe -LO "https://dl.k8s.io/release/v1.28.1/bin/windows/amd64/kubectl.exe"
下载好后,移动到环境变量中的目录里,这里可以移动到 ~/go/bin
查看pods
kubectl get pods
cd {squick_project}
docker build . -t i0gan/squick_src:1.1 -f ./docker/src
docker run -d --name squick_src i0gan/squick_src:1.1
rm -rf ./cache/docker_deploy && mkdir -p cache
docker cp squick_src:/squick/deploy ./cache/docker_deploy
docker build . -t i0gan/squick:1.1 -f ./docker/release
# test
docker run --rm -it --name squick i0gan/squick:1.1
如果从容器中复制文件出来,报 A required privilege is not held by the client 这个错误,请在Windows中打开开发者模式。
export images
docker save -o squick_1.1.tar i0gan/squick:1.1
load images
docker load --input squick_1.1.tar
kind load docker-image i0gan/squick:1.1
# 测试
kubectl run squick --image=i0gan/squick:1.1 --command -- "/squick/script/squick.sh"
# 进入pod
kubectl exec -it squick -- /bin/bash
# 删除pod
kubectl delete pod squick
cd kubernetes/node
kubectl apply -f master.yaml
kubectl logs squick-node-0
kubectl get pods