K8S 1.9.0手动安装

Posted 践行DevOps

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了K8S 1.9.0手动安装相关的知识,希望对你有一定的参考价值。

 

一.安装前提条件

1.关闭防火墙
#systemctl disable firewalld
#systemctl stop firewalld

2.关闭selinux
#setenforce 0
#vi /etc/selinux/config
SELINUX=disabled

3.安装docker 17.03.2
#yum install https://download.docker.com/linux/centos/7/x86_64/stable/Packages/docker-ce-selinux-17.03.2.ce-1.el7.centos.noarch.rpm
#yum install docker-ce-17.03.2.ce-1.el7.centos
#systemctl enable docker
#systemctl start docker

4.配置系统路由参数,防止kubeadm报路由警告
#echo "
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
" >> /etc/sysctl.conf
#sysctl -p

5.下载k8s二进制文件(v1.9.0)版本
https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG-1.9.md#v190
文件名:
kubernetes-server-linux-amd64.tar.gz

6.下载etcd二进制文件(v3.3.5)版本

文件名:etcd-v3.3.5-linux-amd64.tar.gz


二.开始安装

reference: https://blog.csdn.net/chen798213337/article/details/78501042
https://blog.csdn.net/carter115/article/details/50986531

1.master节点操作

#############################部署etcd集群数据库##############################
#cp etcd etcdctl /usr/bin/

#vi /etc/etcd/etcd.conf
ETCD_NAME=ETCD Server
ETCD_DATA_DIR="/var/lib/etcd/"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_ADVERTISE_CLIENT_URLS="http://172.16.68.11:2379"

创建/usr/lib/systemd/system/etcd.service系统服务
[Unit]
Description=Etcd Server
After=network.target

[Service]
Type=simple
WorkingDirectory=/var/lib/etcd
EnvironmentFile=-/etc/etcd/etcd.conf
ExecStart=/usr/bin/etcd

[Install]
WantedBy=multi-user.target


#############################部署kube-apiserver#############################
#cp kube-apiserver kube-controller-manager kube-scheduler kubectl /usr/bin/
#vi /etc/kubernetes/apiserver

KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"
KUBE_API_PORT="--insecure-port=8080"
KUBE_ETCD_SERVERS="--etcd-servers=http://172.16.68.11:2379"
KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=169.169.0.0/16"
KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota"
KUBE_API_LOG="--logtostderr=false --log-dir=/var/log/kubernets --v=2"
KUBE_API_ARGS=" "


#创建/usr/lib/systemd/system/kube-apiserver.service系统服务

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

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

[Install]
WantedBy=multi-user.target


#systemctl enable kube-apiserver
#systemctl start kube-apiserver

#############################部署kube-controller-manager#############################
创建/usr/lib/systemd/system/kube-controller-manager.service系统服务

[Unit]
Description=Kubernetes Controller Manager
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=kube-apiserver.service
Wants=kube-apiserver.service

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

[Install]
WantedBy=multi-user.target

#vi /etc/kubernetes/controller-manager --创建配置文件

KUBE_MASTER="--master=http://172.16.68.11:8080"
KUBE_CONTROLLER_MANAGER_ARGS=" "

#systemctl enable kube-controller-manager
#systemctl start kube-controller-manager

#############################部署kube-scheduler#############################
创建/usr/lib/systemd/system/kube-scheduler.service系统服务

[Unit]
Description=Kubernetes Scheduler
After=kube-apiserver.service
Requires=kube-apiserver.service

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

[Install]
WantedBy=multi-user.target

#vi /etc/kubernetes/scheduler --创建配置文件

KUBE_MASTER="--master=http://172.16.68.11:8080"
KUBE_SCHEDULER_ARGS="--logtostderr=false --log-dir=/var/log/kubernetes --v=2"

#systemctl enable kube-scheduler
#systemctl start kube-scheduler


##################至此,master上的所有服务配置启动完成######################

2.node节点操作

#############################部署kubelet#############################

#cp /tmp/kubernetes/server/bin/kubelet kube-proxy /usr/bin/ 将二进制执行文件复制到/usr/bin下

#vi /etc/kubernetes/config
KUBE_LOGTOSTDERR="--logtostderr=false"
KUBE_LOG_LEVEL="--v=3"
KUBE_ALLOW_PRIV="--allow-privileged=false"

#vi /etc/kubernetes/kubelet
KUBELET_HOSTNAME="--hostname-override=172.16.68.11"
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"


K8S 1.9版本中 kubelet需要注意, kubelet和apiserver连接方式改变,需要额外一个yaml的配置文件kubeconfig

#vi /var/lib/kubelet/kubeconfig
apiVersion: v1
kind: Config
users:
- name: kubelet
clusters:
- name: kubernetes
cluster:
server: http://172.16.68.11:8080
contexts:
- context:
cluster: kubernetes
user: kubelet
name: service-account-context
current-context: service-account-context


#创建/usr/lib/systemd/system/kubelet.service系统服务

[Unit]
Description=Kubernetes Kubelet Server
After=docker.service
Requires=docker.service

[Service]
WorkingDirectory=/var/lib/kubelet
EnvironmentFile=-/etc/kubernetes/config
EnvironmentFile=-/etc/kubernetes/kubelet
ExecStart=/usr/bin/kubelet \
$KUBE_LOGTOSTDERR \
$KUBE_LOG_LEVEL \
$KUBELET_HOSTNAME \
$KUBE_ALLOW_PRIV \
$KUBELET_POD_INFRA_CONTAINER \
$KUBELET_ARGS
Restart=on-failure

[Install]
WantedBy=multi-user.target

# systemctl enable kubelet
# systemctl start kubelet


#############################部署kube-proxy#############################

#vi /etc/kubernetes/proxy
KUBE_PROXY_ARGS="--master=http://172.16.68.11:8080"
s

#创建/usr/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

#systemctl start kube-proxy
#systemctl enable kube-proxy

以上是关于K8S 1.9.0手动安装的主要内容,如果未能解决你的问题,请参考以下文章

k8s手动安装-1

手动安装K8s第四节:Master节点

手动安装K8s第八节:部署Fannel网络

手动安装K8s第六节:node节点部署-kubelet

手动安装K8s 1.10 第二节:基础环境+CA证书

手动安装K8s第五节:master节点kubectl命令部署