# k8s之安装与配置_单机_二进制 ## 环境 | | 说明 | | --- | --- | | 操作系统 | CentOS Linux release 7.7.1908 (Core) | | Docker | 18.06.3-ce | | Kubernetes | v1.16.2 | | Etcd | v3.3.15 | ## 主机规划 | 主机名 | IP | 角色 | 安装应用 | | --- | --- | --- | --- | | k8s-demo3 | 192.168.206.117 | master | kube-apiserver/kube-scheduler/kube-controller-manager/etcd | | k8s-demo3 | 192.168.206.117 | node | docker/kubelet/kube-proxy | > 注: 以上为了说明master和node安装的应用区别才分开写,单机安装所有应用安装一起。 ## 下载 **非常重要: 下载安装包前请阅读 https://kubernetes.io/docs/setup/release/notes/#dependencies** ##### 下载docker离线安装包 https://download.docker.com/linux/static/stable/x86_64/ ![image.jpg](images/docker_download.png) ##### 下载k8s https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG-1.16.md#downloads-for-v1162 ![image.jpg](https://github.com/osoctz/k8s-learning/blob/master/images/k8s.png) ##### 下载etcd https://github.com/etcd-io/etcd/releases/tag/v3.3.15 ![image.jpg](https://github.com/osoctz/k8s-learning/blob/master/images/etcd.png) ##### 下载flanneld https://github.com/coreos/flannel/releases ![image.jpg](https://github.com/osoctz/k8s-learning/blob/master/images/flanneld_dl.png) ## 安装前环境初始化 #防火墙 systemctl stop firewalld systemctl disable firewalld #selinux vi /etc/selinux/config 将SELINUX=enforcing改为SELINUX=disabled,wq保存退出 #关闭swap swapoff -a vi /etc/fstab 将swap那一行注释掉 #目录初始化 mkdir -p /etc/etcd/ mkdir -p /var/lib/etcd/ mkdir -p /etc/kubernetes/ mkdir -p /var/log/kubernetes/ mkdir -p /var/lib/kubelet/ #hosts echo "127.0.0.1 $(hostname)" >> /etc/hosts ## 安装Docker chmod +x ~/install_docker.sh ~/install_docker.sh docker-18.06.3-ce.tgz ## 部署 Master&Node 服务 # 安装命令 tar -zxvf kubernetes-server-linux-amd64.tar.gz cp ~/kubernetes/server/bin/{kube-apiserver,kube-controller-manager,kube-scheduler,kubectl,kube-proxy,kubelet} /usr/bin/ tar -zxvf etcd-v3.3.15-linux-amd64.tar.gz cp ~/etcd-v3.3.15-linux-amd64/{etcd,etcdctl} /usr/bin/ ##### etcd安装 #系统服务配置 cat>/usr/lib/systemd/system/etcd.service</usr/lib/systemd/system/kube-apiserver.service</usr/lib/systemd/system/kube-controller-manager.service</usr/lib/systemd/system/kube-scheduler.service</usr/lib/systemd/system/kube-proxy.service</usr/lib/systemd/system/kubelet.service</var/lib/kubelet/kubeconfig<问题1: 创建POD,kube-controller-manager组件提示“No API token found for service account "default", retry after the token is automatically created and added to the service account” ##### 解决方法 #首先生成密钥 openssl genrsa -out /etc/kubernetes/serviceaccount.key 2048 #kube-apiserver添加参数 KUBE_API_ARGS="--service_account_key_file=/etc/kubernetes/serviceaccount.key" #kube-controller-manager添加参数 KUBE_CONTROLLER_MANAGER_ARGS="--service_account_private_key_file=/etc/kubernetes/serviceaccount.key" >问题2: 创建POD后 kubectl describe 查看提示"kubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. Falling back to "Default" policy" ##### 解决方法 #kubelet添加参数 --hostname-override=all