kubeasz安装单节点K8S
一,下载文件
# 下载工具脚本easzup,举例使用kubeasz版本2.0.2
export release=2.0.2
curl -C- -fLO --retry 3 https://github.com/easzlab/kubeasz/releases/download/${release}/easzup
chmod +x ./easzup
# 使用工具脚本下载
./easzup -D
上述脚本运行成功后,所有文件(kubeasz代码、二进制、离线镜像)均已整理好放入目录/etc/ansible
/etc/ansible 包含 kubeasz 版本为 ${release} 的发布代码
/etc/ansible/bin 包含 k8s/etcd/docker/cni 等二进制文件
/etc/ansible/down 包含集群安装时需要的离线容器镜像
/etc/ansible/down/packages 包含集群安装时需要的系统基础软件
二,配置 ssh 免密登录
三,安装集群
3.1 容器化运行 kubeasz
./easzup -S
3.2 使用默认配置安装 aio 集群
docker exec -it kubeasz easzctl start-aio
备注:
如遇到以下问题
需要更改ansible脚本
/etc/ansible/roles/docker/tasks/main.yml
更改为如下内容
- name: 获取是否已经安装containerd
shell: 'systemctl status containerd|grep Active || echo "NOT FOUND"'
register: containerd_status
- name: 获取是否运行名为'kubeasz'的容器
shell: 'systemctl status docker|grep Active && docker ps|grep kubeasz || echo "NOT FOUND"'
register: install_info
tags: upgrade_docker, download_docker
删除校验dokker状态的task
四,验证安装
如果提示kubectl: command not found,退出重新ssh登录一下,环境变量生效即可
$ kubectl version # 验证集群版本
$ kubectl get componentstatus # 验证 scheduler/controller-manager/etcd等组件状态
$ kubectl get node # 验证节点就绪 (Ready) 状态
$ kubectl get pod --all-namespaces # 验证集群pod状态,默认已安装网络插件、coredns、metrics-server等
$ kubectl get svc --all-namespaces # 验证集群服务状态
root@wuzs:/home/wuzs $ kubectl version
Client Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.0", GitCommit:"e8462b5b5dc2584fdcd18e6bcfe9f1e4d970a529", GitTreeState:"clean", BuildDate:"2019-06-19T16:40:16Z", GoVersion:"go1.12.5", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.0", GitCommit:"e8462b5b5dc2584fdcd18e6bcfe9f1e4d970a529", GitTreeState:"clean", BuildDate:"2019-06-19T16:32:14Z", GoVersion:"go1.12.5", Compiler:"gc", Platform:"linux/amd64"}
root@wuzs:/home/wuzs $ kubectl version
Client Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.0", GitCommit:"e8462b5b5dc2584fdcd18e6bcfe9f1e4d970a529", GitTreeState:"clean", BuildDate:"2019-06-19T16:40:16Z", GoVersion:"go1.12.5", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.0", GitCommit:"e8462b5b5dc2584fdcd18e6bcfe9f1e4d970a529", GitTreeState:"clean", BuildDate:"2019-06-19T16:32:14Z", GoVersion:"go1.12.5", Compiler:"gc", Platform:"linux/amd64"}
root@wuzs:/home/wuzs $ kubectl get componentstatus
NAME STATUS MESSAGE ERROR
controller-manager Healthy ok
scheduler Healthy ok
etcd-0 Healthy {"health":"true"}
root@wuzs:/home/wuzs $ kubectl get node
NAME STATUS ROLES AGE VERSION
192.168.5.131 Ready master 12m v1.15.0
root@wuzs:/home/wuzs $ kubectl get pod --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-797455887b-5svxk 1/1 Running 1 11m
kube-system coredns-797455887b-pvhtj 1/1 Running 1 11m
kube-system heapster-5f848f54bc-f9xp9 1/1 Running 0 11m
kube-system kube-flannel-ds-amd64-kqnm7 1/1 Running 0 12m
kube-system kubernetes-dashboard-5c7687cf8-rv487 1/1 Running 0 11m
kube-system metrics-server-85c7b8c8c4-cdp7z 1/1 Running 0 11m
kube-system traefik-ingress-controller-766dbfdddd-mbqvw 1/1 Running 0 11m
root@wuzs:/home/wuzs $ kubectl get svc --all-namespaces
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default kubernetes ClusterIP 10.68.0.1 443/TCP 12m
kube-system heapster ClusterIP 10.68.171.164 80/TCP 11m
kube-system kube-dns ClusterIP 10.68.0.2 53/UDP,53/TCP,9153/TCP 12m
kube-system kubernetes-dashboard NodePort 10.68.109.232 443:24816/TCP 11m
kube-system metrics-server ClusterIP 10.68.249.62 443/TCP 11m
kube-system traefik-ingress-service NodePort 10.68.168.181 80:23456/TCP,8080:39230/TCP 11m
root@wuzs:/home/wuzs $
五.清理
以上步骤创建的K8S开发测试环境请尽情折腾,碰到错误尽量通过查看日志、上网搜索、提交issues等方式解决;当然你也可以清理集群后重新创建。
在宿主机上,按照如下步骤清理
1.清理集群 docker exec -it kubeasz easzctl destroy 或 docker exec -it kubeasz ansible-playbook /etc/ansible/99.clean.yml
2.清理管理节点
清理运行的容器 easzup -C
清理容器镜像 docker system prune -a
停止docker服务 systemctl stop docker
删除下载文件 rm -rf /etc/ansible /etc/docker /opt/kube
删除docker文件
$ umount /var/run/docker/netns/default
$ umount /var/lib/docker/overlay
$ rm -rf /var/lib/docker /var/run/docker
上述清理脚本执行成功后,建议重启节点,以确保清理残留的虚拟网卡、路由等信息。