频道栏目
首页 > 网络 > 其他 > 正文

体验部署k8s

2019-02-12 09:56:08           
收藏   我要投稿

cat < /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain610.254.12.209 master 10.254.12.161 node EOF

$ systemctl stop firewalld$ systemctl disable firewalld

关闭Selinux

$ setenforce 0

关闭Swap

$ swapoff –a$ sed -i 's/.swap./#&/' /etc/fstab

配置sysctl内核参数 cat < /etc/sysctl.d/k8s.confnet.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF

sysctl -p /etc/sysctl.d/k8s.conf 生效文件

yum install -y wget $ rm -rf /etc/yum.repos.d/*

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base.repo

wget -O /etc/yum.repos.d/epel.repo http://mirrors.cloud.tencent.com/repo/epel-7.repo

yum clean all && yum makecache

配置国内Kubernetes源地址 vi /etc/yum.repos.d/kubernetes.repo[kubernetes]name=Kubernetes baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/enabled=1gpgcheck=1repo_gpgcheck=1gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg

yum install chrony –ysystemctl enable chronyd.service && systemctl start chronyd.service && systemctl status chronyd.servicechronyc sources

配置最低 2CPU 2G内存

yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo 设置docker yum源 yum-config-manager 命令需要依赖 yum-utils yum list docker-ce --showduplicates | sort -r 列出docker版本 yum install -y docker-ce-18.06.1.ce-3.el7 安装18.06.1版本systemctl restart docker && systemctl enable docker && systemctl status docker docker --version

主从节点都要安装:yum install kubectl kubeadm kubelet -y 安装 部署集群用的命令、集群管理工具、集群中每台机器都要运行的组件,负责管理pod及容器的生命周期。systemctl enable kubelet && systemctl start kubelet 暂时启动不了不用管kubeadm config print init-defaults > kubeadm.conf kubeadm建一个配置文件sed -i "s#imageRepository: .#imageRepository: registry.aliyuncs.com/google_containers#g" kubeadm.conf 镜像地址改成国内的sed -i "s/kubernetesVersion: ./kubernetesVersion: v1.13.0/g" kubeadm.conf 指定要安装的版本 kubeadm config images pull --config kubeadm.conf 下载镜像docker images 查已下载镜像列表[root@master ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEregistry.aliyuncs.com/google_containers/kube-proxy v1.13.0 8fa56d18961f 7 weeks ago 80.2MBregistry.aliyuncs.com/google_containers/kube-apiserver v1.13.0 f1ff9b7e3d6e 7 weeks ago 181MBregistry.aliyuncs.com/google_containers/kube-controller-manager v1.13.0 d82530ead066 7 weeks ago 146MBregistry.aliyuncs.com/google_containers/kube-scheduler v1.13.0 9508b7d8008d 7 weeks ago 79.6MBregistry.aliyuncs.com/google_containers/coredns 1.2.6 f59dcacceff4 2 months ago 40MBregistry.aliyuncs.com/google_containers/etcd 3.2.24 3cab8e1b9802 4 months ago 220MBregistry.aliyuncs.com/google_containers/pause 3.1 da86e6ba6ca1 13 months ago 742kB

docker tag 镜像换标签为有k8s.gcr.io标识的镜像下载好后,我们还需要tag下载好的镜像,让下载好的镜像都是带有 k8s.gcr.io 标识的,目前我们从阿里下载的镜像 标识都是,如果不打tag变成k8s.gcr.io,那么后面用kubeadm安装会出现问题,因为kubeadm里面只认 google自身的模式。我们执行下面命令即可完成tag标识更换:

$ docker tag registry.aliyuncs.com/google_containers/kube-apiserver:v1.13.0 k8s.gcr.io/kube-apiserver:v1.13.0

$ docker tag registry.aliyuncs.com/google_containers/kube-controller-manager:v1.13.0 k8s.gcr.io/kube-controller-manager:v1.13.0

$ docker tag registry.aliyuncs.com/google_containers/kube-scheduler:v1.13.0 k8s.gcr.io/kube-scheduler:v1.13.0

$ docker tag registry.aliyuncs.com/google_containers/kube-proxy:v1.13.0 k8s.gcr.io/kube-proxy:v1.13.0

$ docker tag registry.aliyuncs.com/google_containers/pause:3.1 k8s.gcr.io/pause:3.1

$ docker tag registry.aliyuncs.com/google_containers/etcd:3.2.24 k8s.gcr.io/etcd:3.2.24

$ docker tag registry.aliyuncs.com/google_containers/coredns:1.2.6 k8s.gcr.io/coredns:1.2.6

docker rmi 清理下载的镜像

执行完上面tag镜像的命令,我们还需要把带有 registry.aliyuncs.com 标识的镜像删除,执行:

$ docker rmi registry.aliyuncs.com/google_containers/kube-apiserver:v1.13.0

$ docker rmi registry.aliyuncs.com/google_containers/kube-controller-manager:v1.13.0

$ docker rmi registry.aliyuncs.com/google_containers/kube-scheduler:v1.13.0

$ docker rmi registry.aliyuncs.com/google_containers/kube-proxy:v1.13.0

$ docker rmi registry.aliyuncs.com/google_containers/pause:3.1

$ docker rmi registry.aliyuncs.com/google_containers/etcd:3.2.24

$ docker rmi registry.aliyuncs.com/google_containers/coredns:1.2.6

查看下载的镜像列表

执行docker images命令 结果:[root@master ~]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEk8s.gcr.io/kube-proxy v1.13.0 8fa56d18961f 6 weeks ago 80.2 MBk8s.gcr.io/kube-controller-manager v1.13.0 d82530ead066 6 weeks ago 146 MBk8s.gcr.io/kube-scheduler v1.13.0 9508b7d8008d 6 weeks ago 79.6 MBk8s.gcr.io/kube-apiserver v1.13.0 f1ff9b7e3d6e 6 weeks ago 181 MBk8s.gcr.io/coredns 1.2.6 f59dcacceff4 2 months ago 40 MBk8s.gcr.io/etcd 3.2.24 3cab8e1b9802 3 months ago 220 MBk8s.gcr.io/pause 3.1 da86e6ba6ca1 13 months ago 742 kB

部署MASTER

kubeadm init 初始化master节点$ kubeadm init --kubernetes-version=1.13.0 --pod-network-cidr=10.254.12.0/24 --apiserver-advertise-address=10.254.12.209

kubeadm init --kubernetes-version=1.11.2 --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=192.168.0.11

这里我们定义POD的网段为: 10.254.12.0/24,然后api server地址就是master本机IP地址。

同时最后会生成一句话kubeadm join 10.254.12.209:6443 --token 8ezm0e.5icyugj2g9unfmh0 --discovery-token-ca-cert-hash sha256:5888a2b6001a9cde3f015a8fe11cad012a1c1ce980516fe605cb891cc16210ba

这个我们记录下,到时候添加node的时候要用到验证测试

配置kubectl命令$ mkdir -p /root/.kube$ cp /etc/kubernetes/admin.conf /root/.kube/config

执行获取pods列表命令,查看相关状态$ kubectl get pods --all-namespaces

[root@master kubernetes]# kubectl get pods --all-namespaces

NAMESPACE NAME READY STATUS RESTARTS AGE

kube-system coredns-86c58d9df4-92kgg 0/1 Pending 0 7m48s

kube-system coredns-86c58d9df4-q42h5 0/1 Pending 0 7m48s

kube-system etcd-master 1/1 Running 0 7m6s

kube-system kube-apiserver-master 1/1 Running 0 7m16s

kube-system kube-controller-manager-master 1/1 Running 0 7m13s

kube-system kube-proxy-w2sgw 1/1 Running 0 7m48s

kube-system kube-scheduler-master 1/1 Running 0 7m26s

其中coredns pod处于Pending状态,这个先不管。查看集群的健康状态[root@master kubernetes]# kubectl get cs NAME STATUS MESSAGE ERRORscheduler Healthy ok controller-manager Healthy ok etcd-0 Healthy {"health": "true"}

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.10.0/Documentation/kube-flannel.yml

$systemctl restart kube-apiserver$systemctl restart kube-controller-manager$systemctl restart kube-scheduler

安装pod网络插件 这个我还没做到这,待更新kubectl apply -f kubernetes-dashboard.yaml

相关TAG标签 体验 部署 k8s
上一篇:MySQL配置工具
下一篇:根据多个条件删除mysql数据
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站