ubuntu系统中:
一、先安装docker环境
1.安装需要的包
$ sudo apt-get update
2.安装apt依赖包,用于通过HTTPS来获取仓库
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
3.添加Docker的官方GPG秘钥
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
4.设置稳定版仓库
$ sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release-cs) \
stable"
或
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
- 安装docker-ce
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
- 加入开机启动
systemctl start docker
systemctl enable docker
7.配置阿里镜像
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://n0r4xhe6.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
二、开始安装k8s
因为网络限制,不能直接从google进行安装,转为从阿里云的国内镜像进行安装。
依次运行下面的命令:
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
sudo apt-get update && sudo apt-get install -y apt-transport-https curl
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
systemctl daemon-reload
systemctl restart kubelet
8.初始化k8s
先pull阿里的镜像并改名为对应的k8s init时用到的镜像名
再执行
kubeadm init --kubernetes-version v1.18.5 --apiserver-advertise-address ip --pod-network-cidr=10.244.0.0/16
9.配置kubectl
[root@ken ~]# mkdir -p $HOME/.kube
[root@ken ~]# cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
[root@ken ~]# chown $(id -u):$(id -g) $HOME/.kube/config
10.启用kubectl命令的自动补全功能
echo "source <(kubectl completion bash)" >> ~/.bashrc
11.安装POD网络
kubectl apply -f kube-flannel.yml
- 每个节点启动kubelet
systemctl restart kubelet
- 查看node状态
kubectl get nodes
- 查看POD信息
kubectl get pods -n kube-system
15.子节点加入(不用init)
kubeadm join ip:port --token token值 --discovery-token-ca-cert-hash sha256:12312132123123121232312312312312331231
三、安装dashboard
16.dashboard界面
kubectl apply -f recommended.yml
kubectl get pods -n kubernetes-dashboard
kubectl apply -f account.yaml
kubectl create serviceaccount dashboard-admin -n kube-system
kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin
kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk '/dashboard-admin/{print $1}')
常见问题:
1.问题:detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd" ……
解决:
在 /etc/docker/daemon.json 里面加:
{
"exec-opts": ["native.cgroupdriver=systemd"]
}
2.一定要关闭内存交换
sed -i '/swap/s/^/#/' /etc/fstab
swapoff -a
参数立即生效
sysctl -p
- 在node端执行该命令可以查看到该node端上运行的pod的日志情况。
journalctl -f -u kubelet
类似的还有
journalctl -xeu kube-controller-manager --no-pager
journalctl -xeu kube-scheduler --no-pager
journalctl -xeu kubelet --no-pager
-u表示筛选指定标签,此处为kubelet
-f表示跟踪日志
-x表示增加信息解释
-e表示立刻跳转至页面底部
–no-pager表示不将程序的输出内容管道(pipe)给分页程序
网友评论