三、kubernetes環境搭建(實踐)
阿新 • • 發佈:2019-03-13
check off true 查看 wap ima yum 開啟 相關
一、目前近況
docker 版本 K8S支持 18.06的
二、安裝docker
#1.配置倉庫 sudo yum install -y yum-utils device-mapper-persistent-data lvm2 sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo #2.可以查看所有倉庫中所有docker版本,並選擇特定版本安裝 yum list docker-ce --showduplicates | sort -r #安裝docker 版本 K8S支持 高版本為18.06的 sudo yum install docker-ce-18.06.0.ce-3.el7 docker version
默認操作
1、禁用並關閉防火墻或者直接一句話 systemctl stop firewalld & systemctl disable firewalld 2、關閉selinux setenforce 0 3、關閉swap swapoff -a 4、修改host配置使得各主機可通過主機名訪問,方便更新和遷移 echo ‘39.96.69.98 kubernetes-master‘ >> /etc/hosts echo ‘47.94.174.85 kubernetes-node01‘ >> /etc/hosts 5、開啟 br_netfilter kernel module modprobe br_netfilter echo ‘1‘ > /proc/sys/net/bridge/bridge-nf-call-iptables echo ‘1‘ > /proc/sys/net/ipv4/ip_forward 6、配置iptables/netfilter-配置系統內核參數使流過網橋的流量也進入iptables/netfilter框架中,在/etc/sysctl.conf中添加以下配置: echo "net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1" >> /etc/sysctl.conf sysctl -p
三、安裝kubelet、kubeadm、docker
配置阿裏雲源
cat <<EOF > /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64 enabled=1 gpgcheck=0 repo_gpgcheck=0 gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg EOF
安裝
yum install -y kubelet kubeadm kubectl
4、啟動 docker and kublet
systemctl start docker && systemctl enable docker systemctl start kubelet && systemctl enable kubelet
四、下載K8S相關鏡像:
kubeadm init 命令默認使用的docker鏡像倉庫為k8s.gcr.io,國內無法直接訪問,於是需要變通一下。
首先查看需要使用哪些鏡像
kubeadm config images list #輸出如下結果 [root@iZ2zeaqk5x4qdbb3c25vbsZ ~]# kubeadm config images list k8s.gcr.io/kube-apiserver:v1.13.4 k8s.gcr.io/kube-controller-manager:v1.13.4 k8s.gcr.io/kube-scheduler:v1.13.4 k8s.gcr.io/kube-proxy:v1.13.4 k8s.gcr.io/pause:3.1 k8s.gcr.io/etcd:3.2.24 k8s.gcr.io/coredns:1.2.6
1、
docker pull mirrorgooglecontainers/kube-apiserver:v1.13.4 &&
docker tag mirrorgooglecontainers/kube-apiserver:v1.13.4 k8s.gcr.io/kube-apiserver:v1.13.4 && docker rmi mirrorgooglecontainers/kube-apiserver:v1.13.4
2、
docker pull mirrorgooglecontainers/kube-controller-manager:v1.13.4 && docker tag mirrorgooglecontainers/kube-controller-manager:v1.13.4 k8s.gcr.io/kube-controller-manager:v1.13.4 && docker rmi mirrorgooglecontainers/kube-controller-manager:v1.13.4
3、
docker pull mirrorgooglecontainers/kube-scheduler:v1.13.4 && docker tag mirrorgooglecontainers/kube-scheduler:v1.13.4 k8s.gcr.io/kube-scheduler:v1.13.4 && docker rmi mirrorgooglecontainers/kube-scheduler:v1.13.4
4、
docker pull mirrorgooglecontainers/kube-proxy:v1.13.4 && docker tag mirrorgooglecontainers/kube-proxy:v1.13.4 k8s.gcr.io/kube-proxy:v1.13.4 && docker rmi mirrorgooglecontainers/kube-proxy:v1.13.4
5、
docker pull mirrorgooglecontainers/pause:3.1 && docker tag mirrorgooglecontainers/pause:3.1 k8s.gcr.io/pause:3.1 && docker rmi mirrorgooglecontainers/pause:3.1
6、
docker pull mirrorgooglecontainers/etcd:3.2.24 && docker tag mirrorgooglecontainers/etcd:3.2.24 k8s.gcr.io/etcd:3.2.24 && docker rmi mirrorgooglecontainers/etcd:3.2.24
7、
docker pull coredns/coredns:1.2.6 && docker tag coredns/coredns:1.2.6 k8s.gcr.io/coredns:1.2.6 && docker rmi coredns/coredns:1.2.6
五、搭建Master節點(init方式即可)
kubeadm init --kubernetes-version=v1.13.4 --ignore-preflight-errors=NumCPU
kubeadm join 172.17.149.114:6443 --token 1h1k6c.1mo2wfir18fr62pr --discovery-token-ca-cert-hash sha256:469920497b661c121730a7bd373e00098edb5c252daf2eb47c4d0b29e78ddd2c
六、搭建Node節點(join方式即可)
三、kubernetes環境搭建(實踐)