部署docker
bash<(curl -sSL https://cdn.jsdelivr.net/gh/Supermanito/LinuxMirrors@main/DockerInstallation.sh)
选一个合适的源确认安装
创建目录
mkdir /data/soft -p
cd /data/soft/
下载kind
kind指的是Kubernetes IN Docker(用于在 Docker 容器中运行 Kubernetes 集群)
-L 参数表示如果请求的页面发生了重定向,curl 会跟随重定向到新的 URL
-o ./kind 参数指定下载的文件名及其存储位置。在这里,文件将被保存为当前目录下的 kind
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.24.0/kind-linux-amd64
下载部署k8s和kubect1
下载 kubect1l(Kubernetes 的命令行工具),安装然后检查版本
chmod +x ./kind
mv ./kind /usr/bin/kind
kind version
curl -L0 "https://d1.k8s.io/release/$(cur1 -L-s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
kubectl version
下载 kubect1l(Kubernetes 的命令行工具),安装然后检查版本
下载部署kustomize
kustomize,灵活且声明性的方式来组合、补丁和生成 Kubernetes 配置文件,通过不修改原始 YAML 文件的方式来自定义 Kubernetes 资源
wget https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv5.4.3/kustomize_v5.4.3_linux_amd64.tar.gz
tar -zxvf kustomize_v5.4.3_linux_amd64.tar.gz
chmod +x kustomize
cp kustomize /usr/local/bin/ #复制到系统路径
kustomize version #检查是否安装成功
配置 Linux 系统中 inotify 参数,根据当前机器的实际情况来
sysctl fs.inotify.max_user_instances=2280 # 增加用户实例限制
sysctl fs.inotify.max_user_watches=1255368 #增加用户监视器限制,单个用户可以同时监视最多1255360个文件或目录的变化
# fs.inotify.max_user_instances = 2280
# fs.inotify.max _user_watches =1255360
创建并配置集群(kubead)
cat<<EOF | kind create cluster --name=kubeflow --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes :
- role: control-plane
image: kindest/node:v1.31.0@sha256:53df588e04085fd41ae12de0c3fe4c72f7013bba32a20e7325357a1ac94ba865
kubeadmConfigPatches:
- |
kind: ClusterConfiguration
apiServer:
extraArgs:
"service-account-issuer":"kubernetes.default.svc"
"service-account-signing-key-file":"/etc/kubernetes/pki/sa.key'
EOF
配置kubectl并下载manifests
apt install bash-completion
#将bash-completion 加入.bashrc
echo 'source /usr/share/bash-completion/bash completion' >> ~/.bashrc
#为kubectl:添加指令自动补全支持
echo 'source <(kubectl completion bash)'>>~/.bashrc
# 重载配置
source ~/.bashrc
kubectl get nodes
#克降manifests仓库
git clone https://github.com/kubeflow/manifests.git
docker
使用 /root/.docker/config.json 文件中的 Docker 配置信息,创建的 Secret 可以用于在 Pod 中安全地访问私有 Docker 注册表,以便拉取所需的镜像。通过使用 secret,可以避免在 Pod 定义中直接暴露敏感信息
docker login
接下来需要打开浏览器去获取docker授权
复制单次验证码然后登录
在 Kubernetes 集群中创建一个名为regcred的 Secret
kubectl create secret generic regcred --from-file=.dockerconfigjson=/root/.docker/config.json
--type=kubernetes.io/dockerconfigjson
循环尝试构建并应用 Kubernetes 资源,直到成功为止
要进入manifests文件夹内执行
while | kustomize build example | kubectl apply -f-; do echo "Retrying to apply resources";
sleep 20;done
该过程可能持续半小时,耐心等待
查看未成功拉起的pods
kubectl get pods -A| grep -v Running
状态检查
kubectl get ns
kubectl get pods -A -w
#将 Kubernetes中istio-ingressgateway 服务的 88 端口通过本地的 38183 端口转发,使得外部可以访
问服务
kubectl port-forward svc/istio-ingressgateway -n istio-system 38183:80 --address 0.0.0.0
错误排査
pods启动失败
在使用之后发现存在pods启动error类似于
while | kustomize build example | kubectl apply -f -, do echo "Retrying to apply resources";
sleep 20;done
kubectl get pods A -w
以下为可能的解决方案
#查看pods详细信息,看事件events
kubectl describe pod kubeflow-m2m-oidc-configurator-xxx -n istio-system
#检查 Pod 中容器的日志,以找出导致错误的具体原因
kubectl logs kubeflow-m2m-oidc-configurator-xxx -n istio-system
#查看资源占用状况,排查资源问题
htop
# 删除 Pod,然后 Kubernetes 会根据其定义自动创建一个新的 Pod 实例
kubectl delete pod kubeflow-m2m-oidc-configurator-xxx -n istio-system
#检查各个服务端口
kubectl get svc -n kubeflow
#查看数据库的配置参数
env grep MYSQL
#检查网络连通性,用其他pod测试指定mysq1的网络连接状况
#如果 Ping 失败:那么问题出在网络层(Kubernetes 网络插件)。此时可以进一步排査网络问题
kubectl exec -it centraldashboard-5fd97b8c8d-bjwg4 -n kubeflow -- wget http://10.96.5.245:3306
kubectl exec -it centraldashboard-5fd97b8c8d-bjwg4 -n kubeflow -- ping 10.96.5.245
kubectl exec -it katib-mysq1-<pod-id>-n kubeflow -- bash
cat /etc/mysql/my.cnf
#-i:表示交互式,保持标准输入流打开
#-t:表示分配一个伪终端,这样可以在容器内执行命令并看到输出
#-bash:这告诉 Kubernetes 执行 bash,这样你就可以进入 MySQL 容器的命令行界面
ufw allow 80
ufw allow 22/tcp