文章目录
前置条件
执行一下命令
sudo apt install -y gcc g++ make cmake automake autoconf libtool curl unzip protobuf-compiler libssl-dev libcurl4-gnutls-dev libreadline-dev vim-gnome net-tools git htop iftop
sudo apt-get install -y gnupg2
sudo apt-get install software-properties-common
sudo apt-get update
docker安装
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository \
> "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
> $(lsb_release -cs) \
> stable"
设置docker的镜像仓库,大概
sudo apt-get update
更新源
sudo apt-get install docker-ce docker-ce-cli containerd.io
下载安装
sudo docker run hello-world
验证是否安装成功
K8S安装
参考https://kubernetes.io/zh/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/
https://last2win.com/2020/01/30/k8s-install-and-use-and-fix-bug/#dashboard
添加ubuntu代理
touch /etc/profile.d/proxy.sh
vim /etc/profile.d/proxy.sh
允许 iptables 检查桥接流量
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sudo sysctl --system
安装 kubeadm、kubelet 和 kubectl
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl
##下载 Google Cloud 公开签名秘钥这一步需要开启代理
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
将docker的cgroup改为systemd
如不修改,在kubeadm init中会出问题
vim /etc/docker/daemon.json
输入
{
"exec-opts": ["native.cgroupdriver=systemd"]
}
然后重启docker
systemctl daemon-reload
systemctl restart docker
关闭swap
swapoff -a
vim /etc/fstab
改为
启动
systemctl enable kubelet && systemctl start kubelet
初始化kubeadm,这里需要关闭proxy,否者会出现tiemout
kubeadm init \
--apiserver-advertise-address=192.168.197.133 \
--image-repository registry.aliyuncs.com/google_containers \
--pod-network-cidr=10.244.0.0/16
初始化成功提示入如下命令
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
# 启动kubelet 设置为开机自启动
sudo systemctl enable kubelet
# 启动k8s服务程序
sudo systemctl start kubelet
查看节点情况
kubectl get nodes
flannel 配置
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl apply -f kube-flannel.yml
docker pull quay.io/coreos/flannel:v0.15.1-amd64
###v0.15.1的版本信息由kube-flannel.yml中获取,配置时需要自行修改
查看节点信息
kubectl get nodes
Dashboard
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.2.0/aio/deploy/recommended.yaml
kubectl -n kubernetes-dashboard edit service
将type的值改为NodePort
查看端口
kubectl -n kubernetes-dashboard get service