K8s - 使用 Minikube 部署
Docker安装
-- 更新版本
sudo apt-get update
-- 安装必须的包
sudo apt-get install
ca-certificates
curl
gnupg
lsb-release
添加官方GPG密钥
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
设置存储库
echo
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
更新版本
sudo apt-get update
安装最新版
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
运行测试结果
sudo docker run hello-world
Minikube
安装
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
启动(启动后会安装很多必须要的镜像)
minikube start
获取集群所有节点
minikube kubectl get nodes
获取集群所有命名空间
minikube kubectl get namespaces
查看集群所有 Pod
minikube kubectl -- get pods -A
下载 kubectl、kubelet 等工具
snap installkubectl --classic
snap installkubelet --classic
创建 Deployment来管理Pod
kubectl create deployment hello --image=nginx:latest
查看Deployment
kubectl get deployments
查看Pod
kubectl get pods
查看集群事件
kubectl get events
查看 kubectl 配置:
kubectl config view
创建 Service给予外网访问权限
获取Pod的Ip地址
kubectl get pods -o wide
创建service
kubectl expose deployment hello --type=LoadBalancer --port=80
查看service
kubectl get service hello
清理集群资源
首先清除 service、deployment
kubectl delete service hello
kubectl delete deployment hello
停止 Minikube 虚拟机
minikube stop
删除 Minikube 虚拟机
minikube delete
如果需要创建docker用户
groupdel docker
useradd -m docker
passwd docker
修改密码后,加入用户组
gpasswd -a docker docker
vim /etc/sudoers
dockerALL=(ALL)ALL
su docker