1. 程式人生 > >CentOS7.5中安裝kubernetes

CentOS7.5中安裝kubernetes

1 機器環境

1.1 機器1

hostname:k8s-master1
ip:172.16.159.130

1.2 機器2

hostname:k8s-node1
ip:172.16.159.131

1.3 機器3

hostname:k8s-node2
ip:172.16.159.132

2 軟體介紹

2.1 作業系統

centos:CentOS Linux release 7.5.1804
核心:3.10.0-862.el7.x86_64

2.2 Docker

docker:docker-18.03.1-ce.tgz

2.3 etcd

etcd:etcd-v3.2.9-linux-amd64.tar.gz

2.4 flanneld

flanneld:flannel-v0.7.1-linux-amd64.tar.gz

3 安裝步驟

3.1 安裝和配置 docker(master和node節點部署)

k8s-master1,k8s-node1,k8s-node2都得安裝docker。

3.1.1 下載最新的 docker 二進位制檔案

#  mkdir -p /Data/apps/docker
#  cd /Data/apps/docker
#  wget https://download.docker.com/linux/static/stable/x86_64/docker-18.03.1-ce.tgz
#  tar -xvf docker-18.03.1-ce.tgz
#  cp docker/docker* /usr/bin

3.1.2 建立 docker 的 啟動檔案

vi /usr/lib/systemd/system/docker.service

[Unit]
Description=Docker Application Container Engine
Documentation=http://docs.docker.io

[Service]
Environment="PATH=/root/local/bin:/bin:/sbin:/usr/bin:/usr/sbin"
EnvironmentFile=-/run/flannel/docker
ExecStart=/usr/bin/dockerd --log-level=error $DOCKER_NETWORK_OPTIONS
ExecReload=/bin/kill -s HUP $MAINPID
Restart=on-failure
RestartSec=5
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
Delegate=yes
KillMode=process

[Install]
WantedBy=multi-user.target

3.1.3 啟動 dockerd

# systemctl daemon-reload
# systemctl stop firewalld
# systemctl disable firewalld
# iptables -F && iptables -X && iptables -F -t nat && iptables -X -t nat
# systemctl enable docker
# systemctl start docker

3.1.4 檢查 docker 服務

# docker version
Client:
 Version:      18.03.1-ce
 API version:  1.37
 Go version:   go1.9.2
 Git commit:   9ee9f40
 Built:        Thu Apr 26 07:12:25 2018
 OS/Arch:      linux/amd64
 Experimental: false
 Orchestrator: swarm

Server:
 Engine:
  Version:      18.03.1-ce
  API version:  1.37 (minimum version 1.12)
  Go version:   go1.9.5
  Git commit:   9ee9f40
  Built:        Thu Apr 26 07:23:03 2018
  OS/Arch:      linux/amd64
  Experimental: false

3.2 安裝和配置 etcd(master節點部署)

k8s-master1安裝etcd-v3.2.9-linux-amd64.tar.gz

3.2.1 etcd資料庫安裝

# mkdir -p /Data/apps/etcd
# cd /Data/apps/etcd
# wget https://github.com/coreos/etcd/releases/download/v3.2.9/etcd-v3.2.9-linux-amd64.tar.gz
# tar -xvf etcd-v3.2.9-linux-amd64.tar.gz 
# cd etcd-v3.2.9-linux-amd64
# cp etcd etcdctl /usr/bin/

3.2.2 建立etcd作目錄

# mkdir  -p  /var/lib/etcd

3.2.3 建立 etcd 的 啟動檔案

vi /etc/systemd/system/etcd.service

[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target

[Service]
Type=notify
WorkingDirectory=/var/lib/etcd/
EnvironmentFile=-/etc/etcd/etcd.conf          
# set GOMAXPROCS to number of processors
ExecStart=/bin/bash -c "GOMAXPROCS=$(nproc) /usr/bin/etcd --name=\"${ETCD_NAME}\" --data-dir=\"${ETCD_DATA_DIR}\" --listen-client-urls=\"${ETCD_LISTEN_CLIENT_URLS}\""
Restart=on-failure
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

3.2.4 建立配置/etc/etcd/etcd.conf檔案

mkdir -p /etc/etcd/
vi /etc/etcd/etcd.conf

ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_NAME="default"
ETCD_ADVERTISE_CLIENT_URLS="http://0.0.0.0:2379"```

3.2.5 配置開機啟動

# systemctl daemon-reload
# systemctl enable etcd.service
# systemctl start etcd.service

3.2.6 檢驗etcd是否安裝成功

# etcdctl cluster-health
member 8e9e05c52164694d is healthy: got healthy result from http://0.0.0.0:2379
cluster is healthy

3.3 安裝和配置 kubernetes(master節點部署)

k8s-master1安裝kubernetes。

3.3.1 安裝kubernetes 二進位制檔案

#  mkdir -p /Data/apps/k8s
#  cd /Data/apps/k8s
#  wget https://dl.k8s.io/v1.11.1/kubernetes-server-linux-amd64.tar.gz
#  tar -xzvf kubernetes-server-linux-amd64.tar.gz
#  cd kubernetes/server/bin/
#  cp kube-apiserver kube-controller-manager kube-scheduler kubectl /usr/bin/

3.3.2 配置kube-apiserver.service

1 配置kube-apiserver.service啟動專案
vi /usr/lib/systemd/system/kube-apiserver.service

[Unit]
Description=Kubernetes API Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=network.target
After=etcd.service

[Service]
EnvironmentFile=-/etc/kubernetes/config
EnvironmentFile=-/etc/kubernetes/apiserver
ExecStart=/usr/bin/kube-apiserver \
            $KUBE_LOGTOSTDERR \
            $KUBE_LOG_LEVEL \
            $KUBE_ETCD_SERVERS \
            $KUBE_API_ADDRESS \
            $KUBE_API_PORT \
            $KUBELET_PORT \
            $KUBE_ALLOW_PRIV \
            $KUBE_SERVICE_ADDRESSES \
            $KUBE_ADMISSION_CONTROL \
            $KUBE_API_ARGS
Restart=on-failure
Type=notify
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

2 配置kube-apiserver.service引數
mkdir -p /etc/kubernetes/
vi /etc/kubernetes/apiserver

KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"
KUBE_API_PORT="--port=8080"
KUBE_ETCD_SERVERS="--etcd-servers=http://172.16.159.130:2379"
KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=172.17.0.1/16"
KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota"
KUBE_API_ARGS=""

vi /etc/kubernetes/config

KUBE_LOGTOSTDERR="--logtostderr=true"
KUBE_LOG_LEVEL="--v=0"
KUBE_ALLOW_PRIV="--allow-privileged=false"
KUBE_MASTER="--master=http://172.16.159.130:8080"

3.3.3 配置kube-controller-manager

1 配置啟動檔案
vi /usr/lib/systemd/system/kube-controller-manager.service

[Unit]
Description=Kubernetes Controller Manager
Documentation=https://github.com/GoogleCloudPlatform/kubernetes

[Service]
EnvironmentFile=-/etc/kubernetes/config
EnvironmentFile=-/etc/kubernetes/controller-manager
ExecStart=/usr/bin/kube-controller-manager \
            $KUBE_LOGTOSTDERR \
            $KUBE_LOG_LEVEL \
            $KUBE_MASTER \
            $KUBE_CONTROLLER_MANAGER_ARGS
Restart=on-failure
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

2 配置引數
vi /etc/kubernetes/controller-manager

KUBE_CONTROLLER_MANAGER_ARGS=" "

3.3.4 配置kube-scheduler

1 配置啟動檔案
vi /usr/lib/systemd/system/kube-scheduler.service

[Unit]
Description=Kubernetes Scheduler Plugin
Documentation=https://github.com/GoogleCloudPlatform/kubernetes

[Service]
EnvironmentFile=-/etc/kubernetes/config
EnvironmentFile=-/etc/kubernetes/scheduler
ExecStart=/usr/bin/kube-scheduler \
            $KUBE_LOGTOSTDERR \
            $KUBE_LOG_LEVEL \
            $KUBE_MASTER \
            $KUBE_SCHEDULER_ARGS
Restart=on-failure
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

2 配置引數
mkdir -p /Data/logs/kubernetes
vi /etc/kubernetes/scheduler

KUBE_SCHEDULER_ARGS="--logtostderr=true --log-dir=/Data/logs/kubernetes --v=2"

3.3.5 將各元件加入開機自啟

# systemctl daemon-reload 
# systemctl enable kube-apiserver.service
# systemctl start kube-apiserver.service
# systemctl enable kube-controller-manager.service
# systemctl start kube-controller-manager.service
# systemctl enable kube-scheduler.service
# systemctl start kube-scheduler.service

3.3.6 驗證 master 節點功能

# kubectl get componentstatuses
NAME                 STATUS    MESSAGE              ERROR
controller-manager   Healthy   ok                   
scheduler            Healthy   ok                   
etcd-0               Healthy   {"health": "true"}   

3.4 安裝和配置 kubernetes(node節點部署)

k8s-node1,k8s-node2安裝kubernetes。

3.4.1 安裝kubernetes 二進位制檔案

#  mkdir -p /Data/apps/k8s
#  cd /Data/apps/k8s
#  wget https://dl.k8s.io/v1.11.1/kubernetes-server-linux-amd64.tar.gz
#  tar -xzvf kubernetes-server-linux-amd64.tar.gz
#  cd kubernetes/server/bin/
#  cp kube-proxy kubelet /usr/bin/

3.4.2 配置kubelet

1 配置kubelet啟動項
vi /usr/lib/systemd/system/kubelet.service

[Unit]
Description=Kubernetes Kubelet
After=docker.service
Requires=docker.service
[Service]
EnvironmentFile=-/etc/kubernetes/kubelet
ExecStart=/usr/bin/kubelet \
${KUBE_LOGTOSTDERR} \
${KUBE_LOG_LEVEL} \
${NODE_ADDRESS} \
${NODE_PORT} \
${NODE_HOSTNAME} \
${KUBELET_KUBECONFIG} \
${KUBE_ALLOW_PRIV} \
${KUBELET_DNS_IP} \
${KUBELET_DNS_DOMAIN} \
${KUBELET_SWAP}
Restart=on-failure
KillMode=process
[Install]
WantedBy=multi-user.target

2 配置kubelet引數
mkdir -p /etc/kubernetes/
vi /etc/kubernetes/kubelet

 啟用日誌標準錯誤
KUBE_LOGTOSTDERR="--logtostderr=true"
# 日誌級別
KUBE_LOG_LEVEL="--v=0"
# Kubelet服務IP地址
NODE_ADDRESS="--address=172.16.159.131"
# Kubelet服務埠
NODE_PORT="--port=10250"
# 自定義節點名稱
NODE_HOSTNAME="--hostname-override=172.16.159.131"
# kubeconfig路徑,指定連線API伺服器
KUBELET_KUBECONFIG="--kubeconfig=/etc/kubernetes/kubelet.kubeconfig"
# 允許容器請求特權模式,預設false
KUBE_ALLOW_PRIV="--allow-privileged=false"
#KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"
KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0"
# DNS資訊
KUBELET_DNS_IP="--cluster-dns=10.254.0.2"
KUBELET_DNS_DOMAIN="--cluster-domain=cluster.local"
# 禁用使用Swap
KUBELET_SWAP="--fail-swap-on=false"

vi /etc/kubernetes/kubelet.kubeconfig

apiVersion: v1
kind: Config
clusters:
  - cluster:
      server: http://172.16.159.130:8080
    name: local
contexts:
  - context:
      cluster: local
    name: local
current-context: local

vi /etc/kubernetes/config

KUBE_LOGTOSTDERR="--logtostderr=true"
KUBE_LOG_LEVEL="--v=0"
KUBE_ALLOW_PRIV="--allow-privileged=false"
KUBE_MASTER="--master=http://172.16.159.130:8080"

3 啟動 kubelet

# systemctl daemon-reload
# systemctl enable kubelet.service
# systemctl start kubelet.service
# systemctl status kubelet.service

3.4.3 配置kube-proxy

1 配置啟動檔案
vi /usr/lib/systemd/system/kube-proxy.service

[Unit]
Description=Kubernetes Kube-Proxy Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=network.target

[Service]
EnvironmentFile=-/etc/kubernetes/config
EnvironmentFile=-/etc/kubernetes/proxy
ExecStart=/usr/bin/kube-proxy \
            $KUBE_LOGTOSTDERR \
            $KUBE_LOG_LEVEL \
            $KUBE_MASTER \
            $KUBE_PROXY_ARGS
Restart=on-failure
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

2 配置引數
vi /etc/kubernetes/proxy

KUBE_PROXY_ARGS=""

3 啟動 kube-proxy

# systemctl daemon-reload
# systemctl enable kube-proxy
# systemctl start kube-proxy
# systemctl status kube-proxy

3.4.4 檢查節點狀態

進入到k8s-master1機器

[[email protected] k8s]# kubectl get nodes
NAME             STATUS   ROLES    AGE   VERSION
172.16.159.131   Ready    <none>   17m   v1.12.1

3.5 安裝和配置 flanneld(master和node節點部署)

k8s-master1,k8s-node1,k8s-node2都得安裝flanneld。

3.5.1 下載安裝flanneld

# mkdir -p /Data/apps/flannel
# cd /Data/apps/flannel
# wget https://github.com/coreos/flannel/releases/download/v0.7.1/flannel-v0.7.1-linux-amd64.tar.gz
# tar -xzvf flannel-v0.7.1-linux-amd64.tar.gz
# cp flanneld mk-docker-opts.sh /usr/bin

3.5.2 配置flanneld

1 建立啟動檔案
vi /usr/lib/systemd/system/flanneld.service

[Unit]
Description=Flanneld overlay address etcd agent
After=network.target
After=network-online.target
Wants=network-online.target
After=etcd.service
Before=docker.service

[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/flanneld
EnvironmentFile=-/etc/sysconfig/docker-network
ExecStart=/usr/bin/flanneld-start $FLANNEL_OPTIONS
ExecStartPost=/usr/bin/mk-docker-opts.sh -k DOCKER_NETWORK_OPTIONS -d /run/flannel/docker
Restart=on-failure

[Install]
WantedBy=multi-user.target
WantedBy=docker.service

2 配置flanneld配置檔案
mkdir -p /Data/apps/k8s/network
vi /etc/sysconfig/flanneld

# Flanneld configuration options  

# etcd url location.  Point this to the server where etcd runs
FLANNEL_ETCD_ENDPOINTS="http://172.16.159.130:2379"

# etcd config key.  This is the configuration key that flannel queries
# For address range assignment
FLANNEL_ETCD_PREFIX="/Data/apps/k8s/network"

# Any additional options that you want to pass
#FLANNEL_OPTIONS=""

3 配置docker-network
vi /etc/sysconfig/docker-network

DOCKER_NETWORK_OPTIONS=

4 flanneld-star
vi /usr/bin/flanneld-start

#!/bin/sh

exec /usr/bin/flanneld \
        -etcd-endpoints=${FLANNEL_ETCD_ENDPOINTS:-${FLANNEL_ETCD}} \
        -etcd-prefix=${FLANNEL_ETCD_PREFIX:-${FLANNEL_ETCD_KEY}} \
        "[email protected]"

賦執行許可權

chmod +x /usr/bin/flanneld-start

3.5.3 配置etcd中關於flannel的key(只用在k8s-master1上執行)

[[email protected] flannel]# etcdctl set /Data/apps/k8s/network/config '{"Network": "172.20.0.0/16"}'
{"Network": "172.20.0.0/16"}
[[email protected] flannel]# etcdctl get /Data/apps/k8s/network/config
{"Network": "172.20.0.0/16"}
[[email protected] flannel]# 

3.5.4 啟動flanneld

啟動Flannel之後,需要依次重啟docker、kubernete。
1 在master執行:

[[email protected] flannel]# systemctl daemon-reload
[[email protected] flannel]# systemctl enable flanneld.service
[[email protected] flannel]# systemctl start flanneld.service 
[[email protected] flannel]# service docker restart
[[email protected] flannel]# systemctl restart kube-apiserver.service
[[email protected] flannel]# systemctl restart kube-controller-manager.service
[[email protected] flannel]# systemctl restart kube-scheduler.service

2 在node執行:

[[email protected] ~]# systemctl daemon-reload
[[email protected] ~]# systemctl enable flanneld.service 
[[email protected] ~]# systemctl start flanneld.service 
[[email protected] ~]# service docker restart
[[email protected] ~]# systemctl restart kubelet.service
[[email protected] ~]# systemctl restart kube-proxy.service

4 參考文件

相關推薦

CentOS7.5安裝kubernetes - v1.12.1

文章目錄 1 機器環境 1.1 機器1 1.2 機器2 1.3 機器3 2 軟體介紹 2.1 作業系統 2.2 Docker 2.3 etcd 2.4 flanneld

CentOS7.5安裝kubernetes

1 機器環境 1.1 機器1 hostname:k8s-master1 ip:172.16.159.130 1.2 機器2 hostname:k8s-node1 ip:172.16.159.131 1.3 機器3 hostname:k8s-node2 ip:1

CentOS7.5安裝redis5.0(實踐踩坑版)

CentOS7.5中安裝redis5.0(實踐踩坑版) 2018年10月22日 17:01:43 ZerahMu 閱讀數:805 標籤: centOSlinuxredisgrepvim 更多 個人分類: 專案環境 CentOS下Redis的安

CentOS7.5安裝redis5.0

CentOS下Redis的安裝 前言 安裝Redis需要知道自己需要哪個版本,有針對性的安裝,比如如果需要redis GEO這個地理集合的特性,那麼redis版本就不能低於3.2版本,由於這個特性是3.2版本才有的。另外需要注意的是,Redis約定次版本號(即第一個小數點後的數字)為偶數的版本是

Centos7.5安裝JDK1.8環境變數配置

Centos7.5中安裝JDK1.8環境變數配置 在JDK的壓縮包上傳到檔案中後進行解壓。我的是解壓到usr/localjava資料夾中。 解壓之後,就需要進行環境變數的配置 vim /etc/profile  (編輯p

CentOS7.5安裝MySql(實踐踩坑版)

前言 接上篇,SpringBoot從入門到熟悉(二)web開發,在學習springBoot過程中用到了MySql,所以這篇就記錄一下我安裝MySql的詳細過程。因為我是在配置過程中記錄在有道雲筆記的,所以這篇主要就是複製貼上我的雲筆記了。所以,你還會看到一個前言,GGG

在Vmware ESXI6.5安裝pfsense2.34實例

vmware esxi6.5 pfsense現在虛擬機功能越來越強大,在ESXI中配置軟路由或防火墻成為越來越多用戶的選擇,可以利用ESXI主機強大的功能,靈活的配置滿足安裝pfsense的不同的需求。ESXI主機設置一、主機配置要求本教程涉及網絡及硬件的基本要求如下:一臺已安裝好ESXI6.5的虛擬主機:

CentOS7下yum安裝Kubernetes

ddr roo alt ger mem 5.0 services eight 配置文件 1、節點規劃 節點 IP hostname 硬件 master 192.168.80.136 master 內存2G CPU:2*1 node1 192.168.80.

CentOS7.4安裝jdk的幾種方法及配置環境變量

HR 環境 -o OS 安裝jdk 加載類 軟件包 上傳 jre_home 一、下載jdk jdk下載地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Centos7.3安裝MySQL5.7

char confd netstat visio def 遠程 運行 sysconf server 首先安裝相關環境包 yum -y install \ncurses \ncurses-devel \bison \cmake \gcc gcc-c++ 添加MySQL程序

Centos7.3安裝Oracle12C詳細過程

命令行 sim 內存 color oca ble 等於 棧設置 mkdir 安裝Oracle12C 1、下載Oracle12C軟件包 安裝Oracle之前需要在官方網站中下載Oracle12C database 軟件包,官方下載鏈接:http://www.oracle.c

虛擬機CentOS7.5安裝

png 五步 進程 title mil 軟件 sha tex 點擊 Hello,各位,我們今天來學習一下CentOS7.5版本的安裝,眾所周知,想要學習和使用Linux系統,我們就需要用到虛擬機,所以,能夠成功的安裝虛擬機就是一個必不可少的環節,下面我們就來一起看一下吧!

centos7使用kubeadm安裝kubernetes 1.11版本多主高可用

ips refresh www ember issues abi dash iyu let centos7使用kubeadm安裝kubernetes 1.11版本多主高可用 [TOC] kubernetes介紹要學習一個新的東西,先了解它是什麽,熟悉基本概念會有很大幫助。以

CentOS7.5安裝MySQL(5.7版本),掌握MySQL基本操作。

tex RoCE 使用 9.png apache error 需求 結果 加強 當今主流數據庫概略: 在數據庫技術日益發展的今天,主流數據庫代表著成熟的數據庫技術。了解常用數據庫,就能知道數據庫技術發展的程度,以及未來的大體方向。 數據庫分關系型數據庫和非關

CentOS7.5安裝tensorflow和運行tf-faster-rcnn

sci manager 上傳 orm cpu plt 能夠 new ron 一、升級服務器的python版本 0、通過yum安裝後續可能會依賴的包。註意:如果在後續的安裝過程中,遇到缺少某些系統模塊的錯誤的時候,需要通過yum源進行安裝,然後需要重新編譯python。

CentOS 6.5安裝使用dstat資源統計工具

scripts command inodes ftw entos 閱讀 問題 eth0 fin 目錄 1 dstat 工具的使用 1.1 什麽是 dstat 1.2 dstat 的基本使用 1.2.1 dstat 的默認選項 1.2.2 dstat的常用選項 1.3 檢

Centos7.2安裝pip

管理 pip安裝 鼓勵 tps 情況下 c11 我們 cer o-c CentOS安裝python-pip     在使用Python時,需要導入一些第三方工具包,一般情況下,鼓勵使用pip來安裝管理這些第三方的包,     這裏我們來看一下如何在CentOS 7.2

OpenStack教程-02.在CentOS7.5安裝OpenStack-Rocky-系統環境準備-計算節點(其他節點相同)

pen lis cli baseurl make 防火 計算 === 系統 上一篇文章介紹了openstack控制節點的環境配置方法,本篇文章分享一下openstack計算節點的環境配置方法,其他種類節點也基本適用 附:openstack控制節點系統環境配制方法:http

PostgreSQL10.5centos7.5安裝

PostgreSQL10.5在centos7.5上安裝 下載源 安裝伺服器軟體包: 安裝客戶端軟體包: 可選地初始化資料庫並啟用自動啟動: 下面介紹用yum在CentOS 7.5安裝PostgreSQL10.5。

CentOS7.5安裝Mycat連線MySQL8.0

MyCat詳細介紹,請參考https://www.biaodianfu.com/mycat.html 9066管理埠,請參考https://www.cnblogs.com/parryyang/p/5606071.html 1.建立mycat使用者 useradd mycat passwd myca