k8s学习--安装
深入剖析kubernetes--ubuntu18.04安装kubuadm v1.17.2
1、节点布局
节点 | IP | name |
---|---|---|
master | 192.168.116.10 | k8s-master |
node | 192.168.116.11 | k8s-node1 |
node | 192.168.116.12 | k8s-node2 |
2、所有节点安装dockers、kubeadm
docker | 19.03.8 |
---|---|
kubernetes | v1.17.2 |
2.1、安装docker
root@k8s-master:~# cat docker_install.sh
#!/bin/bash
# step 1: 安装必要的一些系统工具
sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
# step 2: 安装GPG证书
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# Step 3: 写入软件源信息
sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
# Step 4: 更新并安装Docker-CE
sudo apt-get -y update
sudo apt-get -y install docker-ce=5:19.03.8~3-0~ubuntu-bionic
2.2、安装kubeadm
由于有网络原因,使用阿里云仓库安装
root@k8s-master:~# cat kube_install.sh
#!/bin/bash
apt-get update && apt-get install -y apt-transport-https
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
echo "deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main" >/etc/apt/sources.list.d/kubernetes.list
apt-get update
apt-get install -y kubeadm=1.17.2-00
关闭swap
swapoff -a
2.3、安装相关组件镜像
root@k8s-master:~# kubeadm config images list --kubernetes-version v1.17.2
k8s.gcr.io/kube-apiserver:v1.17.2
k8s.gcr.io/kube-controller-manager:v1.17.2
k8s.gcr.io/kube-scheduler:v1.17.2
k8s.gcr.io/kube-proxy:v1.17.2
k8s.gcr.io/pause:3.1
k8s.gcr.io/etcd:3.4.3-0
k8s.gcr.io/coredns:1.6.5
#镜像在国外,先下载阿里云镜像,否则速度慢;不下载初始化时会自动从国外下载
root@k8s-master:~# cat images-download.sh
#!/bin/bash
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.17.2
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.17.2
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.17.2
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.17.2
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.4.3-0
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.6.5
2.4、部署 Kubernetes 的 Master 节点
root@k8s-master:~# cat kubeadm.yaml
apiVersion: kubeadm.k8s.io/v1beta2
kind: ClusterConfiguration
controllerManager:
extraArgs:
horizontal-pod-autoscaler-use-rest-clients: "true" #将来部署的 kube-controller-manager 能够使用自定义资源(Custom Metrics)进行自动水平扩展
horizontal-pod-autoscaler-sync-period: "10s"
node-monitor-grace-period: "10s"
apiServer:
extraArgs:
runtime-config: "api/all=true"
imageRepository: registry.cn-hangzhou.aliyuncs.com/google_containers #指定镜像仓库
kubernetesVersion: "v1.17.2"
2.4.1、执行命令init
由于现在kubelet版本过低,最近版为1.23.1,会报错,需要加上–ignore-preflight-errors=KubeletVersion
root@k8s-master:~# kubeadm init --config kubeadm.yaml --ignore-preflight-errors=KubeletVersion
Your Kubernetes control-plane has initialized successfully!
#第一次使用 Kubernetes 集群所需要的配置命令
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/
#给这个 Master 节点添加更多工作节点(Worker)的命令