Kubernetes的安装步骤
更新:HHH   时间:2023-1-7


本篇内容主要讲解“Kubernetes的安装步骤”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Kubernetes的安装步骤”吧!

Kubernetes安装环境

Centos7.1系统的机器3台

Master:192.168.0.120

Nodes:192.168.0.106, 192.168.0.107 

=====

Master

=====

1 在Master上安装kubernetes etcd flannel

yum install kubernetes etcd flannel -y

2 修改配置文件/etc/kubernetes/controller-manager

#指定key文件,key文件可以通过命令生成:openssl genrsa -out /etc/kubernetes/service.key 2048

KUBE_CONTROLLER_MANAGER_ARGS="--service_account_private_key_file=/etc/kubernetes/service.key"

3 修改配置文件/etc/kubernetes/apiserver

# The address on the local server to listen to. 设为全部监听

KUBE_API_ADDRESS="--address=0.0.0.0"

# Comma separated list of nodes in the etcd cluster . 指定etcd节点的地址

KUBE_ETCD_SERVERS="--etcd-servers=http://192.168.0.120:2379"

# Address range to use for services. 这个是设置今后运行Service所在的ip网段

KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=192.168.1.0/24"

# Add your own! 指定key文件

KUBE_API_ARGS="--service_account_key_file=/etc/kubernetes/service.key"

4 修改配置文件/etc/kubernetes/config

# How the controller-manager, scheduler, and proxy find the apiserver

KUBE_MASTER="--master=http://192.168.0.120:8080"

5 修改配置文件/etc/etcd/etcd.conf

ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"

ETCD_ADVERTISE_CLIENT_URLS="http://192.168.0.120:2379"

6 启动etcd和kubernetes的服务

systemctl start etcd kube-apiserver kube-controller-manager kube-scheduler

systemctl enable etcd kube-apiserver kube-controller-manager kube-scheduler

7 修改配置文件/etc/sysconfig/flanneld

# etcd url location.  Point this to the server where etcd runs

FLANNEL_ETCD="http://192.168.0.120:2379"

# etcd config key.  This is the configuration key that flannel queries

# For address range assignment

FLANNEL_ETCD_KEY="/atomic.io/network"

8 设置etcd config的值

# 创建一个文件内容如下,Network指定的IP将为以后容器运行的网段:

cat flannel-config.json

{

  "Network":"172.16.0.0/16",

  "SubnetLen":24,

  "Backend":{

    "Type":"vxlan",

    "VNI":1

  }

}

# 通过文件内容来设置etc的config

etcdctl set atomic.io/network/config < flannel-config.json

9 启动flannel服务 

systemctl start flanneld

systemctl enable flanneld

到这里Master就安装配置完毕,执行下面命令可以查看master信息:

kubectl cluster-info

====

Nodes

====

每个节点上都要做如下的安装配置,这里以107节点为例(已安装docker为前提)

1 安装kubernetes和flannel

yum -y install kubernetes flannel

2 修改/etc/kubernetes/config

KUBE_MASTER="--master=http://192.168.0.120:8080"

3 修改/etc/kubernetes/kubelet

# The address for the info server to serve on (set to 0.0.0.0 or "" for all interfaces)

KUBELET_ADDRESS="--address=0.0.0.0"

# You may leave this blank to use the actual hostname

KUBELET_HOSTNAME="--hostname-override=node107.kuber.com"

# location of the api-server

KUBELET_API_SERVER="--api-servers=http://192.168.0.120:8080"

4 修改/etc/sysconfig/flanneld

# etcd url location.  Point this to the server where etcd runs

FLANNEL_ETCD="http://192.168.0.120:2379"

5 启动flannel和kube相关服务
# 注意Node和Master上启动的kube的服务是不一样的

systemctl start flanneld kube-proxy kubelet

systemctl enable flanneld kube-proxy kubelet

# 重启docker服务

systemctl restart docker

到此,Node节点配置完毕,可以在Master上执行下面命令查看节点信息

kubectl get nodes

到此,相信大家对“Kubernetes的安装步骤”有了更深的了解,不妨来实际操作一番吧!这里是天达云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

返回云计算教程...