这破东西装起来有多蛋疼,试一遍就知道

最近折腾了下Kubernetes的.......安装与卸载,简单记录下过程

用官方的脚本安装k8s应该顺滑无比 (见 kubernetes.io),然而他与google cloud高度整合,安装包基本都在google的域名下,简单来说不是改几行就能搞定的。

安装脚本

  • Gist
  • 使用方法:
    • 安装Master: ./manage.sh master
    • 安装Node: ./manage.sh node {MASTER_IP}
    • 停止并卸载Kubernetes: ./manage.sh down

环境介绍

2 x 阿里云,系统版本如下:

> uname -a

Linux iZ2ze0mfzkjb2ha1p1ct0aZ 3.10.0-514.6.2.el7.x86_64 #1 SMP Thu Feb 23 03:04:39 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

> cat /etc/redhat-release

CentOS Linux release 7.2.1511 (Core)
  • [ 10.86.203.96 ] 作为master
  • [ 10.86.203.97 ] 作为node

准备工作 ( 对应Master和Node )

  • 先更新个镜像源 yum update
  • 然后关掉防火墙,省的之后出麻烦
    systemctl disable firewalld.service
    systemctl stop firewalld.service
    
  • 添加如下内容到/etc/yum.repos.d/virt7-docker-common-release.repo
[virt7-docker-common-release]
    name=virt7-docker-common-release
    baseurl=http://cbs.centos.org/repos/virt7-docker-common-release/x86_64/os/
    gpgcheck=0
  • 通过yum源安装本体及依赖

    yum -y install --enablerepo=virt7-docker-common-release kubernetes etcd flannel

  • 编辑Flannel配置/etc/sysconfig/flanneld

    # Flanneld configuration options

    # etcd url location.  Point this to the server where etcd runs
    FLANNEL_ETCD_ENDPOINTS="http://{换成MasterIP}:2379"

    # etcd config key.  This is the configuration key that flannel queries
    # For address range assignment
    FLANNEL_ETCD_PREFIX="/kube-centos/network"

    # Any additional options that you want to pass
    #FLANNEL_OPTIONS=""
  • 编辑/etc/kubernetes/config如下
    # logging to stderr means we get it in the systemd journal
    KUBE_LOGTOSTDERR="--logtostderr=true"

    # journal message level, 0 is debug
    KUBE_LOG_LEVEL="--v=0"

    # Should this cluster be allowed to run privileged docker containers
    KUBE_ALLOW_PRIV="--allow-privileged=false"

    # How the replication controller and scheduler find the kube-apiserver
    KUBE_MASTER="--master=http://{换成MasterIP}:8080"

Master 节点配置

  • 编辑/etc/etcd/etcd.conf
    # [member]
    ETCD_NAME=default
    ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
    ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"

    #[cluster]
    ETCD_ADVERTISE_CLIENT_URLS="http://0.0.0.0:2379"
  • 编辑/etc/kubernetes/apiserver
  # The address on the local server to listen to.
    KUBE_API_ADDRESS="--address=0.0.0.0"

    # The port on the local server to listen on.
    KUBE_API_PORT="--port=8080"

    # Port kubelets listen on
    KUBELET_PORT="--kubelet-port=10250"

    # Comma separated list of nodes in the etcd cluster
    KUBE_ETCD_SERVERS="--etcd-servers=http://localhost:2379"

    # Address range to use for services
    KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16"

    # Add your own!
    KUBE_API_ARGS=""
  • 启动Etcd并写入虚拟网段

    • systemctl start etcd
    • etcdctl mkdir /kube-centos/network
    • etcdctl mk /kube-centos/network/config "{ \"Network\": \"172.30.0.0/16\", \"SubnetLen\": 24, \"Backend\": { \"Type\": \"vxlan\" } }"
  • 启动服务,报错就检查下之前配置中的IP

for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler flanneld; do
    systemctl restart $SERVICES
    systemctl enable $SERVICES
    systemctl status $SERVICES
done
  • 最后一步,配置kubectl
    • kubectl config set-cluster default-cluster --server=http://{换成MasterIP}:8080
    • kubectl config set-context default-context --cluster=default-cluster --user=default-admin
    • kubectl config use-context default-context

Node 节点配置 (在Master配置完成后)

  • 编辑/etc/kubernetes/kubelet
    # The address for the info server to serve on
    KUBELET_ADDRESS="--address=0.0.0.0"

    # The port for the info server to serve on
    KUBELET_PORT="--port=10250"

    # You may leave this blank to use the actual hostname
    # Check the node number!
    KUBELET_HOSTNAME="--hostname-override=centos-minion-n"

    # Location of the api-server
    KUBELET_API_SERVER="--api-servers=http://{换成MasterIP}:8080"

    # Add your own!
    KUBELET_ARGS=""
  • 启动服务
for SERVICES in kube-proxy kubelet flanneld docker; do
    systemctl restart $SERVICES
    systemctl enable $SERVICES
    systemctl status $SERVICES
done
  • 配置kubectl
    • kubectl config set-cluster default-cluster --server=http://{换成MasterIP}:8080
    • kubectl config set-context default-context --cluster=default-cluster --user=default-admin
    • kubectl config use-context default-context

所以呢

并不能用

Kubernetes的pause-amd64镜像在墙外,需要提前拉到Node本地,这里建议提前把Docker源换成Daocloud什么的方便点。

  • docker pull docker.io/mritd/pause-amd64
  • docker tag docker.io/mritd/pause-amd64 gcr.io/google_containers/pause-amd64:3.0
  • docker tag gcr.io/google_containers/pause-amd64:3.0 gcr.io/google_containers/pause-amd64

之后在任意节点执行kubectl get node都可看到加入的nodes