安装docker
使用ansible 批量部署
ansible 'test_k8s' -u root -m yum -a "name=docker-ce-17.12.1.ce state=present"
配置docker配置文件
vim /etc/docker/daemon.json
{
"ip-forward": true,
"bip": "172.16.51.1/24",
"registry-mirrors": ["https://bo4997m9.mirror.aliyuncs.com","https://registry.docker-cn.com"],
"insecure-registries": ["http://harbor.lianhang.jetair"]
}
“http://harbor.lianhang.jetair” 为自己搭建的私有仓库,见http://www.vservices.top/docs/automated/automated-1asft9gnti93k
批量启动docker
ansible 'test_k8s' -u root -m shell -a 'systemctl start docker && systemctl enable docker'
安装k8s基础组件
批量部署k8syum源
vim k8s.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
使用asible 部署
ansible 'test_k8s' -u root -m copy -a 'src=k8s.repo dest=/etc/yum.repos.d/'
使用ansible 批量安装k8s组件
ansible 'test_k8s' -u root -m yum -a 'name=kubeadm-1.13.3-0,kubelet-1.13.3-0,kubectl-1.13.3-0,kubernetes-cni-0.6.0-0.x86_64 state=present'
kubelet启动忽略swap错误
因为k8s默认不允许使用swap分区,因为是测试环境,所以有可能会用到swap,所以这里在kubelet的systemd文件中加入一条配置,使用ansible来批量部署
复制一台节点的”/etc/systemd/system/kubelet.service.d/10-kubeadm.conf”文件到本地病添加一行配置”EnvironmentFile=”KUBELET_CONFIG_ARGS=—fail-swap-on=false”如下
# Note: This dropin only works with kubeadm and kubelet v1.11+
[Service]
Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf"
Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml"
# This is a file that "kubeadm init" and "kubeadm join" generates at runtime, populating the KUBELET_KUBEADM_ARGS variable dynamically
EnvironmentFile=-/var/lib/kubelet/kubeadm-flags.env
# This is a file that the user can use for overrides of the kubelet args as a last resort. Preferably, the user should use
# the .NodeRegistration.KubeletExtraArgs object in the configuration files instead. KUBELET_EXTRA_ARGS should be sourced from this file.
EnvironmentFile=-/etc/sysconfig/kubelet
Environment="KUBELET_CONFIG_ARGS=--fail-swap-on=false"
Environment="KUBELET_KUBEADM_EXTRA_ARGS=--cgroup-driver=systemd"
ExecStart=
ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARG
使用ansible部署文件
ansible 'test_k8s' -u root -m copy -a 'src=10-kubeadm.conf dest=/etc/systemd/system/kubelet.service.d/10-kubeadm.conf'
使用ansible批量设置kubelet的systemd
ansible 'test_k8s' -u root -m shell -a 'systemctl enable kubelet'
文档更新时间: 2019-07-29 22:08 作者:张尚