Kubernetes installation is considered one of the toughest problems for operators and DevOps. Because Kubernetes can run on various platforms and operating systems, there are so many factors that should be considered during the installation process. In this post, I am going to introduce a new, lightweight tool for installing Kubernetes that supports installation on bare-metal and virtualized servers. Rancher Kubernetes Engine (RKE) is a Kubernetes installer written in Golang. It’s easy to use and doesn’t require a lot of preparation from the user to get started. You can install RKE from the official GitHub repository. You can run RKE from both Linux and MacOS machines. After installation, run the following code to make sure that you have the latest version:
./rke --version rke version v0.0.6-dev ./rke --help NAME: rke - Rancher Kubernetes Engine, Running kubernetes cluster in the cloud USAGE: rke [global options] command [command options] [arguments...] VERSION: v0.0.6-dev AUTHOR(S): Rancher Labs, Inc. COMMANDS: up Bring the cluster up remove Teardown the cluster and clean cluster nodes version Show cluster Kubernetes version config, config Setup cluster configuration help, h Shows a list of commands or help for one command GLOBAL OPTIONS: --debug, -d Debug logging --help, -h show help --version, -v print the versionRKE Prerequistes RKE is a container-based installer, which means it requires Docker to be installed on the remote server, and it currently requires Docker version 1.12 to be installed on the servers. RKE works by connecting to each server via SSH and setting up a tunnel to the Docker socket on this server, which means that the SSH user must have access to the Docker engine on this server. To enable access to the SSH user, you can add this user to the Docker group:
usermod -aG dockerThese are the only preparations the remote servers require to start the Kubernetes installation.Getting Started This example assumes that the user provisioned three servers:
node-1: 192.168.1.5 node-2: 192.168.1.6 node-3: 192.168.1.7THE CLUSTER CONFIG FILE By default, RKE looks for a file called cluster.yml, which contains information about the remote servers and services that will run on servers. The minimum file should look like this:
--- nodes: - address: 192.168.1.5 user: ubuntu role: [controlplane] - address: 192.168.1.6 user: ubuntu role: [worker] - address: 192.168.1.7 user: ubuntu role: [etcd] services: etcd: image: quay.io/coreos/etcd:latest kube-api: image: rancher/k8s:v1.8.3-rancher2 kube-controller: image: rancher/k8s:v1.8.3-rancher2 scheduler: image: rancher/k8s:v1.8.3-rancher2 kubelet: image: rancher/k8s:v1.8.3-rancher2 kubeproxy: image: rancher/k8s:v1.8.3-rancher2The cluster configuration file contains a nodes list. Each node should contain at least these values:
- Address — The SSH IP/FQDN of the server[/]User — An SSH user to connect to the server[/]Role — A list of the host roles: worker, controlplane, or etcd[/]
- etcd — These host(s) can be used to hold the data for the cluster.[/]controlplane — These hosts(s) can be used to hold the Kubernetes API server and other components that are required to run K8s.[/]worker These are the hosts on which your applications can deploy.[/]
➜ ./rke upTo point to the other configuration file, run:
➜ ./rke up --config /tmp/config.ymlYou should see output like this:
➜ ./rke up --config cluster-aws.ymlINFO Building Kubernetes cluster INFO [ssh] Checking private key INFO [ssh] Start tunnel for host [192.168.1.5] INFO [ssh] Start tunnel for host [192.168.1.6] INFO [ssh] Start tunnel for host [192.168.1.7] INFO [certificates] Generating kubernetes certificates INFO [certificates] Generating CA kubernetes certificates INFO [certificates] Generating Kubernetes API server certificates ….INFO [addons] User addon deployed successfully.. INFO Finished building Kubernetes cluster successfullyCONNECTING TO THE CLUSTERRKE will deploy a local file in the same directory that has the config file, which contains kube config information to connect to the newly generated cluster. By default, the kube config file is called
.kube_config_cluster.yml. Copy this file to your local ~/.kube/config to start using
kubectllocally.Note that the deployed local kube config name is relative to the cluster config file. For example, if you used a config filed called mycluster.yml, the local kube config will be named .kube_config_mycluster.yml.
➜ kubectl get nodesNAME STATUS ROLES AGE 192.168.1.5 Ready master 4m v1.8.3-rancher1192.168.1.6 Ready 4m v1.8.3-rancher1A Peek Under the HoodRKE uses the x509 authentication method by default to set authentication between Kubernetes components and for users too. RKE first generates certificates for every component and for the user components as well.
INFO [certificates] Generating kubernetes certificates INFO [certificates] Generating CA kubernetes certificates INFO [certificates] Generating Kubernetes API server certificates INFO [certificates] Generating Kube Controller certificates INFO [certificates] Generating Kube Scheduler certificates INFO [certificates] Generating Kube Proxy certificates INFO [certificates] Generating Node certificate INFO [certificates] Generating admin certificates and kubeconfig INFO [certificates] Deploying kubernetes certificates to Cluster nodesAfter generating certificates, RKE deploys the generated certificates to /etc/kubernetes/ssl to the servers and saves the local kube config file, which contains the master user certificate and can be used later with RKE to remove or upgrade the cluster.RKE then deploys each service component as containers that can communicate with each other. RKE also saves the cluster state in Kubernetes as a config map for later use.RKE is an idempotent tool that can run several times, generating the same output. It can also deploy one of the following network plugins:
- Calico[/]Flannel (default)[/]Canal[/]
network: plugin: calicoAdd-onsRKE supports pluggable add-ons on cluster bootstrap. Users can specify the add-on YAML in the cluster.yml file.RKE deploys the add-ons YAML after the cluster starts. RKE first uploads this YAML file as a config map in the Kubernetes cluster and then runs a Kubernetes job that mounts this config map and deploys the add-ons.
To start using add-ons, use the
Note that RKE doesn’t yet support the removal of add-ons. Once they are deployed the first time, you can’t change them using RKE.
addons:option in the cluster config file. For example:
addons: |- --- apiVersion: v1 kind: Pod metadata: name: my-nginx namespace: default spec: containers: - name: my-nginx image: nginx ports: - containerPort: 80Note that we are using
|-[code]addonsis a multi-line string option, in which you can specify multiple YAML files and separate them with
---.[/code]High AvailabilityThe RKE tool is HA ready. You can specify more than one control plane host in the cluster config file, and RKE will deploy master components on all of them. By default, the kubelets are configured to connect to 127.0.0.1:6443, which is the address of nginx-proxy service that proxies requests to all master nodes.To start an HA cluster, specify more than one host with the role
controlplane, and start the cluster normally.Adding/Removing NodesRKE supports adding/removing nodes for
controlplanehosts. To add additional nodes, you need to update only the cluster config file with additional nodes and run the cluster config with the same file.To remove nodes, just remove them from the nodes list in the cluster configuration file, and re-run the
rke upcommand.The Cluster Remove CommandRKE supports the
rke removecommand. The command does the following:
- Connects to each host and removes the Kubernetes services deployed on it.[/]
- Cleans each host from the directories left by the services:
1、RKE安装实验： https://anjia0532.github.io/2018/01/05/rke/ 2、示例文件cluster.yml： --- auth: strategy: x509 options: foo: bar # supported plugins are: # flannel # calico # canal # weave # # If you are using calico on AWS, use the network plugin config option: # 'cloud_provider: aws' network: plugin: flannel options: flannel_image: quay.io/coreos/flannel:v0.9.1 flannel_cni_image: quay.io/coreos/flannel-cni:v0.2.0 nodes: - address: 192.168.0.2 user: root role: [controlplane, etcd] - address: 192.168.0.3 user: root role: [worker] - address: 192.168.0.4 user: root role: [worker] services: etcd: image: quay.io/coreos/etcd:latest kube-api: image: rancher/k8s:v1.8.3-rancher2 service_cluster_ip_range: 10.233.0.0/18 extra_args: v: 4 kube-controller: image: rancher/k8s:v1.8.3-rancher2 cluster_cidr: 10.233.64.0/18 service_cluster_ip_range: 10.233.0.0/18 scheduler: image: rancher/k8s:v1.8.3-rancher2 kubelet: image: rancher/k8s:v1.8.3-rancher2 cluster_domain: cluster.local cluster_dns_server: 10.233.0.3 infra_container_image: registry.cn-shenzhen.aliyuncs.com/rancher_cn/pause-amd64:3.0 kubeproxy: image: rancher/k8s:v1.8.3-rancher2 system_images: alpine: alpine:latest nginx_proxy: rancher/rke-nginx-proxy:0.1.0 cert_downloader: rancher/rke-cert-deployer:0.1.0 kubedns_image: registry.cn-shenzhen.aliyuncs.com/rancher_cn/k8s-dns-kube-dns-amd64:1.14.5 dnsmasq_image: registry.cn-shenzhen.aliyuncs.com/rancher_cn/k8s-dns-dnsmasq-nanny-amd64:1.14.5 kubedns_sidecar_image: registry.cn-shenzhen.aliyuncs.com/rancher_cn/k8s-dns-sidecar-amd64:1.14.5 kubedns_autoscaler_image: googlecontainer/cluster-proportional-autoscaler-amd64:1.0.0