Kubernetes入门-集群安装

  Kubernetes是谷歌开源的容器集群编排平台,是一个完备的分布式系统支撑平台,为容器化应用提供部署运行、资源调度、服务发现和动态伸缩等一系列完整功能,具有强大的故障发现和自我修复机制、服务滚动升级和在线扩容能力,可扩展资源自动调度机制以及多粒度的资源配额管理能力。
  Kubernetes目前以77%的市场份额独占容器编排平台市场鳌头。目前所有的主要云服务提供商(亚马逊、微软、Google、IBM等)都将其作为部署云原生应用的解决方案。Kubernetes已经在大量企业中落地,并广泛的运用在生产环境中。
作为容器化的主流运行和编排管理平台,Kubernetes的重要性毋庸置疑,以下相关内容只是本人的相关笔记,仅作参考,欢迎业内各路大神指点。

下面是K8S架构简图:

可以看出,K8S架构分Master+Node两部分,其中Master节点作为管理节点,主要提供管理用户相关操作,Node节点作为应用部署节点,实现业务功能,被Master节点管理控制和调度。通过Master和Node节点的各大组件,不难看出,要安装K8S集群,需要分别安装如下组件:

Master节点:

组件名称 组件说明
etcd 非关系型数据库,用于存储相关信息
kube-apiserver 核心通信组件,其他组件通过它实现通信
kube-controller-manager 集群内部管理中心,通过各种manager实现集群管理
kube-scheduler 负责相关调度,比如node上pod的调度

 

 

 

 

Node节点:

组件名称 组件说明
kube-proxy 负责网络通信,相当与代理,实现请求到pod的转发
kubelet node节点核心组件,作为Master节点任务的执行者

 

 

 

安装环境如下:

操作系统 节点角色 节点IP
centOS7.2 X64 Master 120.27.15.116
centOS7.2 X64 node 39.108.85.46

 

 

  

安装过程如下:

step1、安装etcd,这个不属于k8s的东东,直接通过yum install etcd 安装即可

 1 [root@alta-sz kubernetes]# yum install etcd 
 2 Loaded plugins: fastestmirror
 3 Loading mirror speeds from cached hostfile
 4 Resolving Dependencies
 5 --> Running transaction check
 6 ---> Package etcd.x86_64 0:3.2.22-1.el7 will be installed
 7 --> Finished Dependency Resolution
 8 
 9 Dependencies Resolved
10 
11 ========================================================================================================================================================================
12  Package                              Arch                                   Version                                       Repository                              Size
13 ========================================================================================================================================================================
14 Installing:
15  etcd                                 x86_64                                 3.2.22-1.el7                                  extras                                 9.3 M
16 
17 Transaction Summary
18 ========================================================================================================================================================================
19 Install  1 Package
20 
21 Total download size: 9.3 M
22 Installed size: 42 M
23 Is this ok [y/d/N]: y
24 Downloading packages:
25 etcd-3.2.22-1.el7.x86_64.rpm                                                                                                                     | 9.3 MB  00:00:01     
26 Running transaction check
27 Running transaction test
28 Transaction test succeeded
29 Running transaction
30   Installing : etcd-3.2.22-1.el7.x86_64                                                                                                                             1/1 
31   Verifying  : etcd-3.2.22-1.el7.x86_64                                                                                                                             1/1 
32 
33 Installed:
34   etcd.x86_64 0:3.2.22-1.el7                                                                                                                                            
35 
36 Complete!
View Code

安装完进行配置:

vi /etc/etcd/etcd.conf

 1 [root@alta-sz etcd]# vi /etc/etcd/etcd.conf 
 2 
 3 #[Member]
 4 #ETCD_CORS=""
 5 ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
 6 #ETCD_WAL_DIR=""
 7 #ETCD_LISTEN_PEER_URLS="http://localhost:2380"
 8 ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379,http://0.0.0.0:4001"
 9 #ETCD_MAX_SNAPSHOTS="5"
10 #ETCD_MAX_WALS="5"
11 ETCD_NAME="master"
12 #ETCD_SNAPSHOT_COUNT="100000"
13 #ETCD_HEARTBEAT_INTERVAL="100"
14 #ETCD_ELECTION_TIMEOUT="1000"
15 #ETCD_QUOTA_BACKEND_BYTES="0"
16 #ETCD_MAX_REQUEST_BYTES="1572864"
17 #ETCD_GRPC_KEEPALIVE_MIN_TIME="5s"
18 #ETCD_GRPC_KEEPALIVE_INTERVAL="2h0m0s"
19 #ETCD_GRPC_KEEPALIVE_TIMEOUT="20s"
20 
21 #
22 #[Clustering]
23 #ETCD_INITIAL_ADVERTISE_PEER_URLS="http://localhost:2380"
24 ETCD_ADVERTISE_CLIENT_URLS="http://120.27.15.116:2379,http://120.27.15.116:4001"
25 #ETCD_DISCOVERY=""
26 #ETCD_DISCOVERY_FALLBACK="proxy"
27 #ETCD_DISCOVERY_PROXY=""
28 #ETCD_DISCOVERY_SRV=""
29 #ETCD_INITIAL_CLUSTER="default=http://localhost:2380"
30 #ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
31 #ETCD_INITIAL_CLUSTER_STATE="new"
32 #ETCD_STRICT_RECONFIG_CHECK="true"
33 #ETCD_ENABLE_V2="true"
34 #
35 #[Proxy]
36 #ETCD_PROXY="off"
37 #ETCD_PROXY_FAILURE_WAIT="5000"
38 #ETCD_PROXY_REFRESH_INTERVAL="30000"
39 #ETCD_PROXY_DIAL_TIMEOUT="1000"
40 #ETCD_PROXY_WRITE_TIMEOUT="5000"
41 #ETCD_PROXY_READ_TIMEOUT="0"
42 #
43 #[Security]
44 #ETCD_CERT_FILE=""
45 #ETCD_KEY_FILE=""
46 #ETCD_CLIENT_CERT_AUTH="false"
47 #ETCD_TRUSTED_CA_FILE=""
48 #ETCD_AUTO_TLS="false"
49 #ETCD_PEER_CERT_FILE=""
50 #ETCD_PEER_KEY_FILE=""
51 #ETCD_PEER_CLIENT_CERT_AUTH="false"
52 #ETCD_PEER_TRUSTED_CA_FILE=""
53 #ETCD_PEER_AUTO_TLS="false"
54 #
55 #[Logging]
56 #ETCD_DEBUG="false"
57 #ETCD_LOG_PACKAGE_LEVELS=""
58 #ETCD_LOG_OUTPUT="default"
59 #
60 #[Unsafe]
61 #ETCD_FORCE_NEW_CLUSTER="false"
62 #
63 #[Version]
64 #ETCD_VERSION="false"
65 #ETCD_AUTO_COMPACTION_RETENTION="0"
66 #
67 #[Profiling]
68 #ETCD_ENABLE_PPROF="false"
69 #ETCD_METRICS="basic"
70 #
71 #[Auth]
72 #ETCD_AUTH_TOKEN="simple"
View Code

启动etcd,然后测试:

systemctl enable etcd

systemctl start etcd

分别存入一个值{test/key1:123}进行测试

etcdctl set test/key1 123

etcd get test/key1

 1 [root@alta-sz etcd]# etcdctl set test/key1 123
 2 123
 3 [root@alta-sz etcd]# etcdctl get test/key1
 4 123
 5 [root@alta-sz etcd]# 
 6 [root@alta-sz etcd]# 
 7 [root@alta-sz etcd]# 
 8 [root@alta-sz etcd]# etcdctl -C http://localhost:2379 cluster-health
 9 member 8e9e05c52164694d is healthy: got healthy result from http://localhost:2379
10 cluster is healthy
View Code

以上说明etcd安装成功了!

step2、Master节点安装Kubernetes

执行:yum install kubernetes -y

 1 [root@alta-sz k8s]# yum install kubernetes -y
 2 Loaded plugins: fastestmirror
 3 Loading mirror speeds from cached hostfile
 4 Resolving Dependencies
 5 --> Running transaction check
 6 ---> Package kubernetes.x86_64 0:1.5.2-0.7.git269f928.el7 will be installed
 7 --> Processing Dependency: kubernetes-node = 1.5.2-0.7.git269f928.el7 for package: kubernetes-1.5.2-0.7.git269f928.el7.x86_64
 8 --> Processing Dependency: kubernetes-master = 1.5.2-0.7.git269f928.el7 for package: kubernetes-1.5.2-0.7.git269f928.el7.x86_64
 9 --> Running transaction check
10 ---> Package kubernetes-master.x86_64 0:1.5.2-0.7.git269f928.el7 will be installed
11 --> Processing Dependency: kubernetes-client = 1.5.2-0.7.git269f928.el7 for package: kubernetes-master-1.5.2-0.7.git269f928.el7.x86_64
12 ---> Package kubernetes-node.x86_64 0:1.5.2-0.7.git269f928.el7 will be installed
13 --> Processing Dependency: socat for package: kubernetes-node-1.5.2-0.7.git269f928.el7.x86_64
14 --> Processing Dependency: conntrack-tools for package: kubernetes-node-1.5.2-0.7.git269f928.el7.x86_64
15 --> Running transaction check
16 ---> Package conntrack-tools.x86_64 0:1.4.4-3.el7_3 will be installed
17 --> Processing Dependency: libnetfilter_cttimeout.so.1(LIBNETFILTER_CTTIMEOUT_1.1)(64bit) for package: conntrack-tools-1.4.4-3.el7_3.x86_64
18 --> Processing Dependency: libnetfilter_cttimeout.so.1(LIBNETFILTER_CTTIMEOUT_1.0)(64bit) for package: conntrack-tools-1.4.4-3.el7_3.x86_64
19 --> Processing Dependency: libnetfilter_cthelper.so.0(LIBNETFILTER_CTHELPER_1.0)(64bit) for package: conntrack-tools-1.4.4-3.el7_3.x86_64
20 --> Processing Dependency: libnetfilter_queue.so.1()(64bit) for package: conntrack-tools-1.4.4-3.el7_3.x86_64
21 --> Processing Dependency: libnetfilter_cttimeout.so.1()(64bit) for package: conntrack-tools-1.4.4-3.el7_3.x86_64
22 --> Processing Dependency: libnetfilter_cthelper.so.0()(64bit) for package: conntrack-tools-1.4.4-3.el7_3.x86_64
23 ---> Package kubernetes-client.x86_64 0:1.5.2-0.7.git269f928.el7 will be installed
24 ---> Package socat.x86_64 0:1.7.3.2-2.el7 will be installed
25 --> Running transaction check
26 ---> Package libnetfilter_cthelper.x86_64 0:1.0.0-9.el7 will be installed
27 ---> Package libnetfilter_cttimeout.x86_64 0:1.0.0-6.el7 will be installed
28 ---> Package libnetfilter_queue.x86_64 0:1.0.2-2.el7_2 will be installed
29 --> Finished Dependency Resolution
30 
31 Dependencies Resolved
32 
33 ========================================================================================================================================================================
34  Package                                        Arch                           Version                                             Repository                      Size
35 ========================================================================================================================================================================
36 Installing:
37  kubernetes                                     x86_64                         1.5.2-0.7.git269f928.el7                            extras                          36 k
38 Installing for dependencies:
39  conntrack-tools                                x86_64                         1.4.4-3.el7_3                                       base                           186 k
40  kubernetes-client                              x86_64                         1.5.2-0.7.git269f928.el7                            extras                          14 M
41  kubernetes-master                              x86_64                         1.5.2-0.7.git269f928.el7                            extras                          25 M
42  kubernetes-node                                x86_64                         1.5.2-0.7.git269f928.el7                            extras                          14 M
43  libnetfilter_cthelper                          x86_64                         1.0.0-9.el7                                         base                            18 k
44  libnetfilter_cttimeout                         x86_64                         1.0.0-6.el7                                         base                            18 k
45  libnetfilter_queue                             x86_64                         1.0.2-2.el7_2                                       base                            23 k
46  socat                                          x86_64                         1.7.3.2-2.el7                                       base                           290 k
47 
48 Transaction Summary
49 ========================================================================================================================================================================
50 Install  1 Package (+8 Dependent packages)
51 
52 Total download size: 54 M
53 Installed size: 304 M
54 Downloading packages:
55 (1/9): kubernetes-1.5.2-0.7.git269f928.el7.x86_64.rpm                                                                                            |  36 kB  00:00:01     
56 (2/9): conntrack-tools-1.4.4-3.el7_3.x86_64.rpm                                                                                                  | 186 kB  00:00:01     
57 (3/9): kubernetes-client-1.5.2-0.7.git269f928.el7.x86_64.rpm                                                                                     |  14 MB  00:00:02     
58 (4/9): libnetfilter_cttimeout-1.0.0-6.el7.x86_64.rpm                                                                                             |  18 kB  00:00:00     
59 (5/9): libnetfilter_cthelper-1.0.0-9.el7.x86_64.rpm                                                                                              |  18 kB  00:00:00     
60 (6/9): libnetfilter_queue-1.0.2-2.el7_2.x86_64.rpm                                                                                               |  23 kB  00:00:00     
61 (7/9): kubernetes-node-1.5.2-0.7.git269f928.el7.x86_64.rpm                                                                                       |  14 MB  00:00:00     
62 (8/9): socat-1.7.3.2-2.el7.x86_64.rpm                                                                                                            | 290 kB  00:00:00     
63 (9/9): kubernetes-master-1.5.2-0.7.git269f928.el7.x86_64.rpm                                                                                     |  25 MB  00:00:01     
64 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
65 Total                                                                                                                                    17 MB/s |  54 MB  00:00:03     
66 Running transaction check
67 Running transaction test
68 Transaction test succeeded
69 Running transaction
70   Installing : kubernetes-client-1.5.2-0.7.git269f928.el7.x86_64                                                                                                    1/9 
71   Installing : kubernetes-master-1.5.2-0.7.git269f928.el7.x86_64                                                                                                    2/9 
72   Installing : socat-1.7.3.2-2.el7.x86_64                                                                                                                           3/9 
73   Installing : libnetfilter_cthelper-1.0.0-9.el7.x86_64                                                                                                             4/9 
74   Installing : libnetfilter_queue-1.0.2-2.el7_2.x86_64                                                                                                              5/9 
75   Installing : libnetfilter_cttimeout-1.0.0-6.el7.x86_64                                                                                                            6/9 
76   Installing : conntrack-tools-1.4.4-3.el7_3.x86_64                                                                                                                 7/9 
77   Installing : kubernetes-node-1.5.2-0.7.git269f928.el7.x86_64                                                                                                      8/9 
78   Installing : kubernetes-1.5.2-0.7.git269f928.el7.x86_64                                                                                                           9/9 
79   Verifying  : libnetfilter_cttimeout-1.0.0-6.el7.x86_64                                                                                                            1/9 
80   Verifying  : libnetfilter_queue-1.0.2-2.el7_2.x86_64                                                                                                              2/9 
81   Verifying  : kubernetes-node-1.5.2-0.7.git269f928.el7.x86_64                                                                                                      3/9 
82   Verifying  : kubernetes-client-1.5.2-0.7.git269f928.el7.x86_64                                                                                                    4/9 
83   Verifying  : kubernetes-master-1.5.2-0.7.git269f928.el7.x86_64                                                                                                    5/9 
84   Verifying  : libnetfilter_cthelper-1.0.0-9.el7.x86_64                                                                                                             6/9 
85   Verifying  : conntrack-tools-1.4.4-3.el7_3.x86_64                                                                                                                 7/9 
86   Verifying  : socat-1.7.3.2-2.el7.x86_64                                                                                                                           8/9 
87   Verifying  : kubernetes-1.5.2-0.7.git269f928.el7.x86_64                                                                                                           9/9 
88 
89 Installed:
90   kubernetes.x86_64 0:1.5.2-0.7.git269f928.el7                                                                                                                          
91 
92 Dependency Installed:
93   conntrack-tools.x86_64 0:1.4.4-3.el7_3                kubernetes-client.x86_64 0:1.5.2-0.7.git269f928.el7     kubernetes-master.x86_64 0:1.5.2-0.7.git269f928.el7    
94   kubernetes-node.x86_64 0:1.5.2-0.7.git269f928.el7     libnetfilter_cthelper.x86_64 0:1.0.0-9.el7              libnetfilter_cttimeout.x86_64 0:1.0.0-6.el7            
95   libnetfilter_queue.x86_64 0:1.0.2-2.el7_2             socat.x86_64 0:1.7.3.2-2.el7                           
96 
97 Complete!
View Code

安装完成可以分别查看如下目录文件:

 step3、配置Master节点,Master节点需要配置config、apiserver、controller-manager、schduler

1、config配置:vi /etc/kubernetes/config  主要配置其中的参数KUBE_MASTER

 

2、apiserver配置:vi /etc/kubernetes/apiserver  

参数说明:

KUBE_API_ADDRESS:ApiServer监听IP地址,配置为0.0.0.0,监听所有

KUBE_API_PORT:ApIServer监听端口

KUBE_ETCD_SERVERS:ETCD存储服务器IP+PORT

 

3、controller-manager配置:保持默认即可

4、schduler配置:保持默认即可

 

step4、启动Master节点

启动apiserver:

systemctl enable kube-apiserver.service
systemctl start kube-apiserver.service

启动controller-manager:
systemctl enable kube-controller-manager.service
systemctl start kube-controller-manager.service

启动scheduler:

systemctl enable kube-scheduler.service

systemctl start kube-scheduler.service

至此,Master节点就安装完成了,下面继续Node节点的安装。

 

step5、安装Node节点

yum install kubernetes -y    安装和Master的步骤相同

step6、配置Node节点、Node节点需要配置config、kubelet、proxy

1、配置config:vi /etc/kubernetes/config 

2、配置kubelet:vi /etc/kubernetes/kublet

 

3、配置proxy:保持默认即可

step7、启动Node节点

启动kubelet:

systemctl enable kubelet.service

systemctl startkubelet.service

启动proxy:

systemctl enable kube-proxy.service

systemctl startkube-proxy.service

step8、测试验证

 到Master节点执行:kubectl get nodes  如下,node节点成功加入到Master。

 

一个简单的Kubernetes集群就搭建起来了。

 

posted on 2018-11-25 15:13  funnyboy0128  阅读(578)  评论(0编辑  收藏  举报

导航