- 一、环境准备
- 操作系统 CentOS 7.X
- 内存 2G 【至少】
- CPU 2核【至少】
- 硬盘 20G 【至少】
1.1 yum 源
1.2关闭防火墙,关闭selinux
#systemctl stop firewalld & systemctl disable firewalld
#setenforce 0
1.3关闭swap
#sed -i '/ swap / s/^/#/' /etc/fstab
1.4 系统环境
vi /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward=1
net.ipv4.tcp_tw_recycle=0
vm.swappiness=0
vm.overcommit_memory=1
vm.panic_on_oom=0
fs.inotify.max_user_watches=89100
fs.file-max=52706963
fs.nr_open=52706963
net.ipv6.conf.all.disable_ipv6=1
net.netfilter.nf_conntrack_max=2310720
echo “* soft nofile 65536” >> /etc/security/limits.conf
echo “* hard nofile 65536” >> /etc/security/limits.conf
echo “* soft nproc 65536” >>/etc/security/limits.conf
echo “* hard nproc 65536” >>/etc/security/limits.conf
echo “* soft memlock unlimited” >> /etc/security/limits.conf
echo “* hard memlock unlimited” >>/etc/security/limits.conf
二、docker安装
2.1安装docker
#yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#yum install docker-ce -y
#docker --version
#systemctl start docker & systemctl enable docker
2.2配置加速
#mkdir -p /etc/docker
#vi /etc/docker/daemon.json
{ "registry-mirrors": ["https://27zv9ros.mirror.aliyuncs.com"] }
#systemctl daemon-reload
#systemctl restart docker
三、主节点安装
3.1 安装kubernetes
vi /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
#yum -y install kubeadm kubelet kubectl --disableexcludes=kubernetes
#systemctl enable kubelet && systemctl start kubelet
3.2拉取镜像
#kubeadm config images list
//用kubeadm查看master上所需的镜像,下载并导入相关的镜像
#docker pull mirrorgooglecontainers/kube-controller-manager:v1.15.0
#docker pull mirrorgooglecontainers/kube-apiserver:v1.15.0
#docker pull mirrorgooglecontainers/kube-scheduler:v1.15.0
#docker pull mirrorgooglecontainers/kube-proxy:v1.15.0
#docker pull mirrorgooglecontainers/pause:3.1
#docker pull mirrorgooglecontainers/etcd:3.3.10
#docker pull coredns/coredns:1.3.1
打标记
#docker tag mirrorgooglecontainers/kube-proxy:v1.15.0 http://k8s.gcr.io/kube-proxy:v1.15.0
#docker tag mirrorgooglecontainers/kube-scheduler:v1.15.0 http://k8s.gcr.io/kube-scheduler:v1.15.0
#docker tag mirrorgooglecontainers/kube-apiserver:v1.15.0 http://k8s.gcr.io/kube-apiserver:v1.15.0
#docker tag mirrorgooglecontainers/kube-controller-manager:v1.15.0 http://k8s.gcr.io/kube-controller-manager:v1.15.0
#docker tag mirrorgooglecontainers/etcd:3.3.10 http://k8s.gcr.io/etcd:3.3.10
#docker tag coredns/coredns:1.3.1 http://k8s.gcr.io/coredns:1.3.1
#docker tag mirrorgooglecontainers/pause:3.1 http://k8s.gcr.io/pause:3.1
#######删除未打标记的镜像,可不操作##########################33
#docker rmi mirrorgooglecontainers/kube-apiserver:v1.15.0
#docker rmi mirrorgooglecontainers/kube-controller-manager:v1.15.0
#docker rmi mirrorgooglecontainers/kube-scheduler:v1.15.0
#docker rmi mirrorgooglecontainers/kube-proxy:v1.15.0
#docker rmi mirrorgooglecontainers/pause:3.1
#docker rmi mirrorgooglecontainers/etcd:3.3.10
#docker rmi coredns/coredns:1.3.1
#docker images
3.3初始化
#kubeadm init --pod-network-cidr=10.1.0.0/16 --kubernetes-version=v1.15.0 --apiserver-advertise-address=192.168.1.100
注意:此处末尾会有提示,需要在执行的命令
#mkdir -p $HOME/.kube
#cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
#chown $(id -u):$(id -g) $HOME/.kube/config
初始化生成token一定要记录下来,后边在node节点使用kubeadm join往集群中添加节点时会用到。
# kubeadm join 192.168.0.102:6443 --token ij6at3.ehwxgh7vccsouuj5 --discovery-token-ca-cert-hash sha256:a580d31f70262a442734796dac01c27963106e41750c5339dc3fb6e3e769eec6 --ignore-preflight-errors=Swap
# kubeadm token create --print-join-command 找回以上信息
3.4下载flannel网络
#wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
#kubectl apply -f kube-flannel.yml
离线版 https://github.com/coreos/flannel/releases
四、work节点安装
4.1镜像拉取
kube-proxy、pause、coredns、flannel(手动部署)
镜像的版本信息需要根据实际情况进行相应的修改。通过docker tag命令修改为kubeadm查到的标签即可。
#docker pull mirrorgooglecontainers/kube-proxy:v1.15.0
#docker pull mirrorgooglecontainers/pause:3.1
#docker pull coredns/coredns:1.3.1
#docker tag mirrorgooglecontainers/kube-proxy:v1.15.0 http://k8s.gcr.io/kube-proxy:v1.15.0
#docker tag coredns/coredns:1.3.1 http://k8s.gcr.io/coredns:1.3.1
#docker tag mirrorgooglecontainers/pause:3.1 http://k8s.gcr.io/pause:3.1
##############可不操作###############3
#docker rmi mirrorgooglecontainers/kube-proxy:v1.15.0
#docker rmi mirrorgooglecontainers/pause:3.1
#docker rmi coredns/coredns:1.3.1
#docker images
4.2加入集群
#yum -y install kubeadm
#kubeadm join 192.168.1.100:6443 --token 16iqqc.w0j8vrrqwyq1kx7x --discovery-token-ca-cert-hash sha256:5936509b58b84c0d7fe2aad932ccb6f806a131b0cc6262304fbff4fd94192749
注:如果因为没有在master执行网络附件。
需要重新执行加入的时候先重置命令:kubeadm reset
加入后,在master执行kubectl get nodes READY即可
五、测试
查看各个节点得pod状态
pod状态为Pending、ContainerCreating、ImagePullBackOff 都表明 Pod 没有就绪,Running 才是就绪状态。
如果有pod提示Init:ImagePullBackOff,说明这个pod的镜像在对应节点上拉取失败,我们可以通过 kubectl describe pod 查看 Pod 具体情况,以确认拉取失败的镜像:
kubectl logs podnome -n kube-system查看日志
#kubectl get pod --all-namespaces -o wide
#kubectl describe pod coredns-86c58d9df4-lrc44 --namespace=kube-system
#kubectl get componentstatus #查看组件运行状态
#kubectl get nodes #查看各个节点的信息
#kubectl get ns #查看命名空间
#kubectl get pod -n kube-system -o wide#查看命名空间kube-system中容器的启动情
况
#kubectl exec pod_name -c container_name -it -- /bin/bash #进入pod中的容器
六、dashboard面板管理
1) #docker pull http://k8s.gcr.io/kubernetes-dashboard-amd64
#kubectl apply -f kubernetes-dashboard-http.yml
2)docker load -i dashboard.tar ##下载tar包然后执行
七、命令介绍
#kubectl exec -ti <your-pod-name> -n <your-namespace> -- /bin/sh
//进入pod