一、目前近况
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 /etc/hosts和/etc/hostname区别 /etc/hosts主要是ip和域名的对应 /etc/hostname主要是本地主机域名(本地主机名修改过后需要重启服务器才能生效) 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方式即可)
执行join命令 kubeadm join 172.17.149.114:6443 --token 1h1k6c.1mo2wfir18fr62pr --discovery-token-ca-cert-hash sha256:469920497b661c121730a7bd373e00098edb5c252daf2eb47c4d0b29e78ddd2c
获取对外IP地址名利:curl ipinfo.io
注意:
cp /etc/kubernetes/admin.conf $HOME/ chown $(id -u):$(id -g) $HOME/admin.conf export KUBECONFIG=$HOME/admin.conf
docker启动命令,docker重启命令,docker关闭命令 启动 systemctl start docker 守护进程重启 sudo systemctl daemon-reload 重启docker服务 systemctl restart docker 重启docker服务 sudo service docker restart 关闭docker service docker stop 关闭docker systemctl stop docker
1.获取节点 #kubectl get nodes 2.创建 #kubectl create -f webserver.yaml 3.查看创建的状态,状态为Pending【准备中】,Running状态【已经创建成功】 #kubectl get pods 4.查看该容器在哪个节点 #kubectl get pods -o wide 5.查看该容器的所有状态 #kubectl get pods httpd -o yaml 6.删除Pod #kubectl delete pod httpd 7.进入Pod对应的容器内部 kubectl exec -it rc-jenkins-3049460636-lppbn /bin/bash
https://blog.csdn.net/qianghaohao/article/details/82624920 #kubeadm reset 解决join执行如上命令后报错如下(提示 10250 端口被占用)