在centos7上搭建k8s1.9.9

#! /bin/bash

# 在centos7上手动安装k8s1.9.9参考#https://www.cnblogs.com/peterinblog/p/8124746.html

# 二进制软件下载地址:https://github.com/coreos/etcd/releases #https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG-1.9.md

# https://github.com/coreos/etcd/releases

# 本次采用master-worker一个主节点和一个工作节点 master:192.168.29.102 #worker:192.168.29.103

# 对于基础环境,比如配置本地yum、关闭防火墙或者开放相关端口、SELINUX这些事先需要准备好。

# master 都是用的root权限,所以没注意权限的问题

# etcd需要采用奇数个节点,因需通过选举产升leader

# 1、下载文件

mkdir /data && cd /data

wget https://github.com/coreos/etcd/releases/download/v3.3.9/etcd-v3.3.9-linux-amd64.tar.gz # master

wget https://dl.k8s.io/v1.9.9/kubernetes-server-linux-amd64.tar.gz #master

# wget https://dl.k8s.io/v1.9.9/kubernetes-node-linux-amd64.tar.gz # worker

# 2、解压etcd并移动文件

tar -zxvf etcd-v3.3.9-linux-amd64.tar.gz && etcd-v3.3.9-linux-amd64

mv etcd* /usr/bin

# 3、etcd配置文件

mkdir /etc/etcd

cat <<EOF >>/etc/etcd/etcd.conf

ETCD_NAME=ansible-k8s2

ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"

ETCD_DATA_DIR="/var/lib/etcd/"

ETCD_ADVERTISE_CLIENT_URLS="http://192.168.29.102:2379"

EOF

# 4、解压k8s文件并移动文件至/usr/bin

tar -zxvf kubernetes-server-linux-amd64.tar.gz && cd kubernetes/server/bin/

mv kube-apiserver kube-controller-manager kube-scheduler kube-proxy kubelet kubectl /usr/bin

# 5、k8s相关配置文件

mkdir /etc/kubernetes && cd /etc/kubernetes

# apiserver

cat <<EOF >>apiserver

#

# The following values are used to configure the kube-apiserver

#

# The address on the local server to listen to.

#KUBE_API_ADDRESS="--address=0.0.0.0"

KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"

# The port on the local server to listen on.

KUBE_API_PORT="--port=8080"

# Port minions listen on

#KUBELET_PORT="--kubelet-port=10250"

# Comma separated list of nodes in the etcd cluster

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

# Address range to use for services

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

# default admission control policies

KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,ResourceQuota"

# Add your own!

KUBE_API_ARGS=""

EOF

# config

cat <<EOF >>config

KUBE_LOGTOSTDERR="--logtostderr=true"

KUBE_LOG_LEVEL="--v=0"

KUBE_ALLOW_PRIV="--allow-privileged=false"

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

EOF

# controller-manager

cat <<EOF >>controller-manager

KUBE_CONTROLLER_MANAGER_ARGS=""

EOF

# scheduler

cat <<EOF >>scheduler

KUBE_SCHEDULER_ARGS=""

EOF

# 6、etcd k8s 启动文件

# etcd

cat <<EOF >>/lib/systemd/system/etcd.service

[Unit]

Description=Etcd Server

Documentation=https://github.com/coreos/etcd

After=network.target

[Service]

User=root

Type=notify

EnvironmentFile=-/etc/etcd/etcd.conf

ExecStart=/usr/bin/etcd

Restart=on-failure

RestartSec=10s

LimitNOFILE=40000

[Install]

WantedBy=multi-user.target

EOF

# apiserver

cat <<EOF >>/lib/systemd/system/kube-apiserver.service

[Unit]

Description=Kubernetes API Server

Documentation=https://github.com/GoogleCloudPlatform/kubernetes

After=network.target

After=etcd.service

Wants=etcd.service

[Service]

User=root

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

EOF

# controller-manager

cat <<EOF >>/lib/systemd/system/kube-controller-manager.service

[Unit]

Description=Kubernetes Controller Manager

Documentation=https://github.com/GoogleCloudPlatform/kubernetes

After=etcd.service

After=kube-apiserver.service

Requires=etcd.service

Requires=kube-apiserver.service

[Service]

User=root

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

EOF

# scheduler

cat <<EOF >>/lib/systemd/system/kube-scheduler.service

[Unit]

Description=Kubernetes Scheduler

Documentation=https://github.com/kubernetes/kubernetes

[Service]

User=root

EnvironmentFile=-/etc/kubernetes/config

EnvironmentFile=-/etc/kubernetes/scheduler

ExecStart=/usr/bin/kube-scheduler \

$KUBE_LOGTOSTDERR \

$KUBE_MASTER

Restart=on-failure

LimitNOFILE=65536

[Install]

WantedBy=multi-user.target

EOF

# 7、开启启动

systemctl daemon-reload

for service in etcd.service kube-apiserver.service kube-controller-manager.service kube-scheduler.service;

do systemctl enable $service;

done

# 8、启动并查看状态

for service in etcd.service kube-apiserver.service kube-controller-manager.service kube-scheduler.service;

do systemctl start $service;

done

for service in etcd.service kube-apiserver.service kube-controller-manager.service kube-scheduler.service;

do systemctl status $service;

done

# worker

# 1、下载、解压并移动文件

wget wget https://dl.k8s.io/v1.9.9/kubernetes-node-linux-amd64.tar.gz

tar -zxvf kubernetes-node-linux-amd64.tar.gz && cd cd kubernetes/node/bin/

mv kube* /usr/bin

# 2、配置文件

# config

mkdir -p /etc/kubernetes && cd /etc/kubernetes

cat <<EOF >>config

KUBE_LOGTOSTDERR="--logtostderr=true"

KUBE_LOG_LEVEL="--v=3"

KUBE_ALLOW_PRIV="--allow-privileged=false"

#KUBE_MASTER="--master=http://192.168.29.102:8080" 版本不支持了

EOF

#kubeconfig

mkdir /var/lib/kubelet

cat <<EOF >>/var/lib/kubelet/kubeconfig

apiVersion: v1

kind: Config

users:

- name: kubelet

clusters:

- name: kubernetes

cluster:

server: http://192.168.29.102:8080

contexts:

- context:

cluster: kubernetes

user: kubelet

name: service-account-context

current-context: service-account-context

EOF

# kubelet

cat <<EOF >>kubelet

#KUBELET_ADDRESS="--address=127.0.0.1"

KUBELET_HOSTNAME="--hostname-override=192.168.29.103"

#KUBELET_API_SERVER="--api-servers=http://192.168.29.102:8080"

# pod infrastructure container

KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"

KUBELET_ARGS="--enable-server=true --enable-debugging-handlers=true --fail-swap-on=false --kubeconfig=/var/lib/kubelet/kubeconfig"

EOF

# proxy

cat <<EOF >>proxy

KUBE_PROXY_ARGS=""

EOF

# 3、启动文件

cat <<EOF >>/lib/systemd/system/kubelet.service

[Unit]

Description=Kubernetes Kubelet

Documentation=https://github.com/GoogleCloudPlatform/kubernetes

After=docker.service #

Requires=docker.service # 先安装docker启动了再启动worker

[Service]

WorkingDirectory=/var/lib/kubelet

EnvironmentFile=-/etc/kubernetes/config

EnvironmentFile=-/etc/kubernetes/kubelet

ExecStart=/usr/bin/kubelet \

$KUBE_LOGTOSTDERR \

$KUBE_LOG_LEVEL \

$KUBELET_API_SERVER \

$KUBELET_ADDRESS \

$KUBELET_PORT \

$KUBELET_HOSTNAME \

$KUBE_ALLOW_PRIV \

$KUBELET_POD_INFRA_CONTAINER \

$KUBELET_ARGS

Restart=on-failure

KillMode=process

[Install]

WantedBy=multi-user.target

EOF

#proxy

cat <<EOF >>/lib/systemd/system/kube-proxy.service

[Unit]

Description=Kubernetes Proxy

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

EOF

# 4、安装docker 我是通过rpm安装的 最好通过yum安装,不用管依赖的问题

cd /data/

yum -y install container-selinux libcgroup libltdl.so.7 pigz libtool-ltdl

rpm -ivh docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm --nodeps #可能涉及到依赖问题

# 5、开机启动

systemctl daemon-reload

for service in docker.service kube-proxy.service kubelet.service;

do systemctl enable $service;

done

# 6、启动worker

for service in docker.service kube-proxy.service kubelet.service;

do systemctl start $service;

done

# 在master上检查

[root@ansible-k8s2 system]# kubectl get nodes

NAME STATUS ROLES AGE VERSION

192.168.29.103 Ready <none> 16h v1.9.9

[root@ansible-k8s2 system]# kubectl get cs

NAME STATUS MESSAGE ERROR

controller-manager Healthy ok

etcd-0 Healthy {"health":"true"}

scheduler Healthy ok

# 注意:如果执行kubectl提示cannot excute binary file 这是下载的文件在解压后出现的问题,我这边是重新解压再移动就可以了

github地址:https://github.com/chances-for-those-who-have-prepared/study/blob/master/k8s/install_k8s_by_manual

如有问题,可在github地址:https://github.com/chances-for-those-who-have-prepared/study/issues说明

本文分享自微信公众号 - 没有故事的陈师傅(mygsdcsf)

原文出处及转载信息见文内详细说明,如有侵权,请联系 yunjia_community@tencent.com 删除。

原始发表时间:2018-08-01

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏Happy的分享

SpringBoot+JWT+SpringSecurity+MybatisPlus实现Restful鉴权脚手架

JWT(json web token)的无状态鉴权方式,越来越流行。配合SpringSecurity+SpringBoot,可以实现优雅的鉴权功能。

19340
来自专栏Golang语言社区

深入理解channel:设计+源码

channel是大家在Go中用的最频繁的特性,也是Go最自豪的特性之一,你有没有思考过:

37120
来自专栏机器学习算法与Python学习

极客程序员的最爱,全面屏科幻终端模拟器——eDEX-UI

eDEX-UI 全面屏且跨平台的终端模拟器应用程序,他有点类似于科幻计算机界面,它被用于大型触摸屏,但可以在普通台式机,笔记本电脑或平板电脑上很好地工作,因为它...

19020
来自专栏sktj

Go json

7910
来自专栏吉浦迅科技

用Jetson NANO做个机器狗?

注意是“准备”阶段....Wilk表示:This Project is heavily work in progress and may change ever...

45620
来自专栏AI研习社

什么是插入排序算法?

大家好,我是Sanjula,在这个教程中,我希望告诉你一些关于插入排序算法的知识,包括:

10220
来自专栏芋道源码1024

Apache Dubbo 服务框架,不限国内,有哪些替代品?

来源:https://www.zhihu.com/question/34101033/answer/743107819

22130
来自专栏程序员修炼之路

Git找回回滚后的内容和删除的文件

32920
来自专栏相约机器人

通过数据讲述3个温布尔登故事

大满贯网球比赛的统计数据使得弹药数据故事无止境。从一个国家的成功看一段时间; 男女比赛之间的差异; 比较四个不同的比赛。

11040
来自专栏相约机器人

超全Python速查表登上GitHub热榜,标星4600+ | 资源

GitHub上出现一份对Python用户非常友好的资源:Python Cheatsheet。

14210

扫码关注云+社区

领取腾讯云代金券

年度创作总结 领取年终奖励