k8s-环境搭建
categories: []
date: '2023-10-26T10:58:06.462440+08:00'
tags: []
title: k8s-环境搭建
updated: 2023-11-13T16:41:49.495+8:0
搭建环境
- 虚拟机:Ubuntu 22.04
- 虚拟机配置4C/4G
- 使用
minikube
搭建 - 配置
proxychains
;在下面wget
curl
等下载文件时不能正常下载时使用
参考
- https://icybersec.gitbook.io/cybersecuritynote/yun-wei-pei-zhi/kubernetes/an-zhuang-bu-shu#an-zhuang-minikube
- https://blog.csdn.net/QiVictory/article/details/119535043
开始搭建
安装docker
apt install -y docker.io
go语言环境-编译cri-dockerd的go版本要大于1.9.1
- 第一种,官方,执行
./installer_linux
报错的话建议第二种,
wget https://storage.googleapis.com/golang/getgo/installer_linux
chmod +x ./installer_linux
./installer_linux
source ~/.bash_profile
- 第二种
wget -c https://dl.google.com/go/go1.20.4.linux-amd64.tar.gz -O - | sudo tar -xz -C /usr/local
export PATH=$PATH:/usr/local/go/bin
- go 切换国内源
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
安装 cri-dockerd
git clone https://github.com/Mirantis/cri-dockerd.git
cd cri-dockerd
mkdir bin
go build -o bin/cri-dockerd
mkdir -p /usr/local/bin
install -o root -g root -m 0755 bin/cri-dockerd /usr/local/bin/cri-dockerd
cp -a packaging/systemd/* /etc/systemd/system
sed -i -e 's,/usr/bin/cri-dockerd,/usr/local/bin/cri-dockerd,' /etc/systemd/system/cri-docker.service
systemctl daemon-reload
systemctl enable cri-docker.service
systemctl enable --now cri-docker.socket
build -o bin/cri-dockerd
编译报错可以使用下面命令,注意go的版本
go build -o bin/cri-dockerd -mod=readonly
修改/etc/systemd/system/cri-docker.socket
服务
vim /etc/systemd/system/cri-docker.socket
SocketGroup=docker
改为
SocketGroup=root
创建软连接
ln -s /usr/local/bin/cri-dockerd /usr/bin/cri-dockerd
然后重启服务服务
systemctl daemon-reload
systemctl restart cri-docker.socket
查看这两个服务是否正常
systemctl status cri-docker.service
systemctl status cri-docker.socket
安装crictl
wget https://github.com/kubernetes-sigs/cri-tools/releases/download/v1.26.0/crictl-v1.26.0-linux-amd64.tar.gz
sudo tar zxvf crictl-v1.26.0-linux-amd64.tar.gz -C /usr/local/bin
rm -f zxvf crictl-v1.26.0-linux-amd64.tar.gz
ln -s /usr/local/bin/crictl /usr/bin/crictl
安装kubectl
curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
kubectl version --client
- kubectl 执行报错,建议一直重新下载,我个人搭建时候下载好几次才成功
安装Minikube
apt install conntrack -y
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube
sudo mkdir -p /usr/local/bin/
sudo install minikube /usr/local/bin/
查看可支持的版本
minikube config defaults kubernetes-version
启动集群
- 根据大佬命令没有成功启动
minikube start --image-mirror-country=cn --driver=none --kubernetes-version=1.23.15
- 第二种
minikube start --force
- 配置代理(可选)
export HTTP_PROXY=http://ip:端口
export HTTPS_PROXY=https://ip:端口
export NO_PROXY=localhost,127.0.0.1,10.96.0.0/12,192.168.59.0/24,192.168.49.0/24,192.168.39.0/24##
查看pods
kubectl get pods --all-namespaces
启动metrics
minikube addons enable metrics-server
需要同时启动以下两条命令,建议使用screen分别执行
- 启动仪表盘
minikube dashboard
- 配置对外端口
kubectl proxy --port=8088 --address='0.0.0.0' --accept-hosts='^.*'
- 访问
http://192.168.72.129:8088/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy
搭建完成
本文是原创文章,采用 CC BY-NC-ND 4.0 协议,完整转载请注明来自 putdown.top