安装docker

使用ansible 批量部署
  1. ansible 'test_k8s' -u root -m yum -a "name=docker-ce-17.12.1.ce state=present"
配置docker配置文件
  1. vim /etc/docker/daemon.json
  2. {
  3. "ip-forward": true,
  4. "bip": "172.16.51.1/24",
  5. "registry-mirrors": ["https://bo4997m9.mirror.aliyuncs.com","https://registry.docker-cn.com"],
  6. "insecure-registries": ["http://harbor.lianhang.jetair"]
  7. }

http://harbor.lianhang.jetair” 为自己搭建的私有仓库,见http://www.vservices.top/docs/automated/automated-1asft9gnti93k

批量启动docker
  1. ansible 'test_k8s' -u root -m shell -a 'systemctl start docker && systemctl enable docker'

安装k8s基础组件

批量部署k8syum源
  1. vim k8s.repo
  2. [kubernetes]
  3. name=Kubernetes
  4. baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
  5. enabled=1
  6. gpgcheck=1
  7. repo_gpgcheck=1
  8. gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
使用asible 部署
  1. ansible 'test_k8s' -u root -m copy -a 'src=k8s.repo dest=/etc/yum.repos.d/'
使用ansible 批量安装k8s组件
  1. 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”如下
  1. # Note: This dropin only works with kubeadm and kubelet v1.11+
  2. [Service]
  3. Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf"
  4. Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml"
  5. # This is a file that "kubeadm init" and "kubeadm join" generates at runtime, populating the KUBELET_KUBEADM_ARGS variable dynamically
  6. EnvironmentFile=-/var/lib/kubelet/kubeadm-flags.env
  7. # This is a file that the user can use for overrides of the kubelet args as a last resort. Preferably, the user should use
  8. # the .NodeRegistration.KubeletExtraArgs object in the configuration files instead. KUBELET_EXTRA_ARGS should be sourced from this file.
  9. EnvironmentFile=-/etc/sysconfig/kubelet
  10. Environment="KUBELET_CONFIG_ARGS=--fail-swap-on=false"
  11. Environment="KUBELET_KUBEADM_EXTRA_ARGS=--cgroup-driver=systemd"
  12. ExecStart=
  13. ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARG
使用ansible部署文件
  1. 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
  1. ansible 'test_k8s' -u root -m shell -a 'systemctl enable kubelet'
文档更新时间: 2019-07-29 22:08   作者:张尚