Build k8s1.9.9 on centos7

#! /bin/bash

Manually install k8s1.9.9 on centos7 Reference#https://www.cnblogs.com/peterinblog/p/8124746.html

Binary software download address: https://github.com/coreos/etcd/releases #https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG-1.9.md

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

This time using master-worker, a master node and a worker node master: 192.168.29.102 #worker: 192.168.29.103

For the basic environment, such as configuring local yum, closing the firewall or opening related ports, SELINUX, these need to be prepared in advance.

Master uses root privileges, so I didn’t pay attention to permissions

etcd needs to use an odd number of nodes, because the leader must be promoted through election

1、 download file

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、 Unzip etcd and move files

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

mv etcd* /usr/bin

3、 etcd configuration file

mkdir /etc/etcd

cat <>/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、 Unzip the k8s file and move the file to /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 related configuration files

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

apiserver

cat <>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 <>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 <>controller-manager

KUBE_CONTROLLER_MANAGER_ARGS=""

EOF

scheduler

cat <>scheduler

KUBE_SCHEDULER_ARGS=""

EOF

6、 etcd k8s startup file

etcd

cat <>/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 <>/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 <>/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 <>/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、 Turn on

systemctl daemon-reload

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

do systemctl enable $service;

done

8、 Start and view status

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、 Download, unzip and move files

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、 Configuration file

config

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

cat <>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" version is not supported

EOF

kubeconfig

mkdir /var/lib/kubelet

cat <>/var/lib/kubelet/kubeconfig

apiVersion: v1

kind: Config

users:

clusters:

cluster:

server: http://192.168.29.102:8080

contexts:

cluster: kubernetes

user: kubelet

name: service-account-context

current-context: service-account-context

EOF

kubelet

cat <>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 <>proxy

KUBE_PROXY_ARGS=""

EOF

3、 Startup file

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

[ Unit]

Description=Kubernetes Kubelet

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

After=docker.service #

Requires=docker.service # Install docker first and then start 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 <>/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、 Install docker I installed it through rpm, it is best to install it through yum, regardless of dependency

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 #May involve dependency issues

5、 boot

systemctl daemon-reload

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

do systemctl enable $service;

done

6、 Start worker

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

do systemctl start $service;

done

Check on master

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

NAME STATUS ROLES AGE VERSION

192.168.29.103 Ready 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

Note: If you execute kubectl and prompt “cannot excute binary file”, this is a problem that occurs after the downloaded file is decompressed. I just need to re-decompress and move it.

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

If you have any questions, please refer to the github address: https://github.com/chances-for-those-who-have-prepared/study/issues

Recommended Posts

Build k8s1.9.9 on centos7
Jenkins build on centos
Build MariaDB replication on CentOS
Build Elasticsearch 6.2.4 (centos) based on docker
Build Nginx environment on Linux (CentOS)
Build Discuz Forum based on CentOS
CentOS7 build jenkins
Centos build lnmp
Centos7 build python3.8.5+scrapy+gerapy
Build WeChat applet service based on CentOS
Build WeChat applet service based on CentOS
CentOS7 build FastDFS distributed file system (on)
CentOS7.3 64 bit, build Zabbix3.4
Install Docker on Centos7
CentOS build private git
Build Nginx based on Centos 7 (including virtual host)
install LNMP on centos7.4
Install Java on Centos 7
Xfs configuration on centos7
CentOS6.7 build LNMP environment
Configure Ocserv on CentOS 6
CentOS7.3.1611 deploys k8s1.5.2 cluster
Centos6.9 build rabbitmq 3.6.8 cluster
Nodejs install on centos7
Install FFmpeg on CentOS 8
Centos7.6 build LNMP environment
K8S: (1) A preliminary study on CentOS stand-alone deployment
Install RabbitMQ on CentOS 7
Install Node.js on Centos
Centos7 build Kubernetes cluster
Maven install on centos7
Install MongoDB on CentOS 7
Install Surelog on CentOS8
Build Hadoop in CentOS
Deploy vuepress on centos7
Openjdk install on centos7
Centos7 build DNS service
Install Jenkins on centos7
Use RapidSVN on CentOS7
install RabbitMQ on centos
Install RabbitMQ on CentOS 7
install Docker on centos6.5
How to build a LAMP environment on centos7.2
CentOS7 deploys k8s cluster
install oracle on centos
Install Elasticsearch 6 on centos7
Install RabbitMQ on CentOS7
Deploy Jenkin on centos7
CentOS 7 build LNMP environment
3 minutes to teach you to build gitea on Centos server
Use Rancher to build a K8s cluster under CentOS7
Build docker environment under Centos6.5
CentOs7.3 build Solr stand-alone service
Build OpenV** Server under CentOS7
CentOs7.3 build RabbitMQ 3.6 stand-alone service
Build zabbix monitoring zabbix4.2 in CentOS7.6
Install ElasticSearch 7.x on CentOS 7
Build OpenLDAP server under CentOS7
Glusterfs cluster installation on Centos7
Build zabbix monitoring zabbix4.2 in CentOS7.6
Install MySQL 8.0.16 on Linux Centos