preface

Kubernetes study notes, write them down! 💻 🚀

Prepare three CentOS 7.0+ machines, change the Hostname to Master, node-01, and Node-02:

node The IP address
Master 10.211.55.7
node-01 10.211.55.8
node-02 10.211.55.9

I have created three new virtual machines:

Configure the /etc/hosts file for all machines:

vi /etc/hosts
Copy the code

Add the following three lines and save and exit.

10.211.55.7 Master
10.211.55.8 node-01
10.211.55.9 node-02
Copy the code

Disabling the Firewall

1. Run sudo systemctl stop firewalld.service to disable the firewall

2. Run the sudo systemctl disable firewalld.service command to disable the system startup

Check the firewall status: firewall-cmd –state

Check whether the systemctl is-enabled firewalld.service command is used to start the system

Disable SELINUX

sudo setenforce 0
sudo vi /etc/selinux/config
Change #SELINUX to disabled
SELINUX=disabled
Copy the code

None example Disable the Swap partition

To disable the Swap command, run the following command:

swapoff -a
Copy the code

In addition, you need to modify the /etc/fstab file to comment out the automatic mounting of SWAP to prevent SWAP from being enabled after the machine restarts. Use the following command:

vi /etc/fstab
Copy the code

Comment the swap line and save and exit.

# /dev/mapper/centos-swap swap swap defaults 0 0
Copy the code

To confirm that swap is closed, run the following command:

free -m
Copy the code

If the swap output is 0, the swap is disabled.

Start the installation

yum -y install epel-release
Copy the code

Then upgrade to the latest version:

yum update
Copy the code

Start installation :(for all hosts)

yum install -y etcd kubernetes-master ntp flannel
Copy the code

Etcd 3.3.11, Flannel 0.7.1 and Kubernetes-Master 1.5.2 are installed.

Continue installing Node:

yum install -y kubernetes-node ntp flannel docker
Copy the code

Time check :(all hosts)

systemctl start ntpd
ntpdate ntp1.aliyun.com
hwclock -w
Copy the code

Configure the ETCD server

  • Master: edit etcd. Conf file:
vim /etc/etcd/etcd.conf
Copy the code

Modify it to the following:

ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380"
ETCD_LISTEN_CLIENT_URLS="Http://0.0.0.0:2379, http://0.0.0.0:4001
ETCD_NAME="master"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://10.211.55.7:2380"
ETCD_ADVERTISE_CLIENT_URLS="Http://10.211.55.7:2379, http://10.211.55.7:4001
ETCD_INITIAL_CLUSTER="Master = http://10.211.55.7:2380, node01 = http://10.211.55.8:2380, node02 = http://10.211.55.9:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"
Copy the code

Check whether to modify:

grep -v '^ #' /etc/etcd/etcd.conf
Copy the code

Start the ETcd service

systemctl start etcd
Copy the code

Check the ETCD cluster status

etcdctl cluster-health
Copy the code

Check the list of etCD cluster members. There is only one

etcdctl  member  list
Copy the code

  • Node01: Edit the etcd.conf file:
vim /etc/etcd/etcd.conf
Copy the code

Modify it to the following:

ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380"
ETCD_LISTEN_CLIENT_URLS="Http://0.0.0.0:2379, http://0.0.0.0:4001
ETCD_NAME="node02"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://10.211.55.8:2380"
ETCD_ADVERTISE_CLIENT_URLS="Http://10.211.55.8:2379, http://10.211.55.8:4001
ETCD_INITIAL_CLUSTER="Master = http://10.211.55.7:2380, node01 = http://10.211.55.8:2380, node02 = http://10.211.55.9:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"
Copy the code

Start the ETcd service

systemctl start etcd
Copy the code

Check the ETCD cluster status

etcdctl cluster-health
Copy the code

Check the etCD cluster member list

etcdctl  member  list
Copy the code
  • Node02:

Edit the etcd.conf file:

vim /etc/etcd/etcd.conf
Copy the code

Modify it to the following:

ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="http://0.0.0.0:2380"
ETCD_LISTEN_CLIENT_URLS="Http://0.0.0.0:2379, http://0.0.0.0:4001
ETCD_NAME="node02"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://10.211.55.9:2380"
ETCD_ADVERTISE_CLIENT_URLS="Http://10.211.55.9:2379, http://10.211.55.9:4001
ETCD_INITIAL_CLUSTER="Master = http://10.211.55.7:2380, node01 = http://10.211.55.8:2380, node02 = http://10.211.55.9:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"
Copy the code

Start the ETcd service

systemctl start etcd
Copy the code

Check the ETCD cluster status

etcdctl cluster-health
Copy the code

Check the etCD cluster member list

etcdctl  member  list
Copy the code

Configuring the Master Server

1) Configure the kube-Apiserver profile

[root@Master ~]# grep -v ‘^#’ /etc/kubernetes/config

KUBE_LOGTOSTDERR="--logtostderr=true"
KUBE_LOG_LEVEL="--v=0"
KUBE_ALLOW_PRIV="--allow-privileged=false"
KUBE_MASTER="-- master = http://10.10.10.14:8080"
Copy the code

[root@Master ~]# grep -v ‘^#’ /etc/kubernetes/apiserver

KUBE_API_ADDRESS="-- insecure - bind - address = 0.0.0.0"
KUBE_ETCD_SERVERS="-- etcd - the servers = http://10.10.10.14:2379"
KUBE_SERVICE_ADDRESSES="- service - cluster - IP - range = 10.254.0.0/16"
KUBE_ADMISSION_CONTROL="--admission-control=AlwaysAdmit"
KUBE_API_ARGS=""
Copy the code

2) Configure the kube-Controller-manager configuration file

[root@Master ~]# grep -v ‘^#’ /etc/kubernetes/controller-manager

KUBE_CONTROLLER_MANAGER_ARGS=""
Copy the code

3) Configure the kube-Scheduler configuration file

[root@Master ~]# grep -v ‘^#’ /etc/kubernetes/scheduler

KUBE_SCHEDULER_ARGS="- the address = 0.0.0.0"
Copy the code

4) Start the service

for i in  kube-apiserver kube-controller-manager kube-scheduler;do systemctl restart $i; systemctl enable $i;done
Copy the code

Configure the node01 server

1) the configuration etcd

/ root @ Master ~ # etcdctl set/atomic. IO/network/config ‘{” network “:” along / 16 “}’

{"Network": "Along / 16"}
Copy the code

2) Configure the Node1 network. In this example, flannel is used. For other methods, please refer to the official website of Kubernetes.

[root@node01 ~]# grep -v ‘^#’ /etc/sysconfig/flanneld

FLANNEL_ETCD_ENDPOINTS="http://10.211.55.8:2379"
FLANNEL_ETCD_PREFIX="/atomic.io/network"
FLANNEL_OPTIONS=""
Copy the code

View authentication network information

[root@Master ~]# etcdctl get /atomic.io/network/config

{ "Network": "Along / 16" }
Copy the code

[root@Master ~]# etcdctl ls /atomic.io/network/subnets

/ atomic. IO/network/subnets / 172.16.69.0-24 / atomic. IO/network/subnets / 172.16.6.0-24Copy the code

/ root @ Master ~ # etcdctl get/atomic. IO/network/subnets / 172.16.6.0-24

{"PublicIP":"10.211.55.8"}
Copy the code

/ root @ Master ~ # etcdctl get/atomic. IO/network/subnets / 172.16.69.0-24

{"PublicIP":"10.211.55.9"}
Copy the code

3) Configure node1 kube-proxy

[root@node01 ~]# grep -v ‘^#’ /etc/kubernetes/config

KUBE_LOGTOSTDERR="--logtostderr=true"
KUBE_LOG_LEVEL="--v=0"
KUBE_ALLOW_PRIV="--allow-privileged=false"
KUBE_MASTER="-- master = http://10.10.10.14:8080"
Copy the code

[root@node01 ~]# grep -v ‘^#’ /etc/kubernetes/proxy

KUBE_PROXY_ARGS="-- bind = address = 0.0.0.0"
Copy the code

4) Configure node1 kubelet

[root@node01 ~]# grep -v ‘^#’ /etc/kubernetes/kubelet

KUBELET_ADDRESS="- the address = 127.0.0.1"
KUBELET_HOSTNAME="- the hostname - override = 10.10.10.15"
KUBELET_API_SERVER="- API - the servers = http://10.10.10.14:8080"
KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"
KUBELET_ARGS=""
Copy the code

5) Start the node01 service

for i in flanneld kube-proxy kubelet docker;do systemctl restart $i; systemctlenable $i; systemctl status$i ;done
Copy the code

Configure the node02 server

The configurations for node2 and node1 are the same except for the following

[root@node2 ~]# vi /etc/kubernetes/kubelet

KUBELET_HOSTNAME="- the hostname - override = 10.211.55.9"
Copy the code

Look at the node

[root@Master ~]# kubectl get nodes

NAME          STATUS    AGE
10.211.55.8   Ready     18h
10.211.55.9   Ready     13h
Copy the code

The last

“Some roads, go on, will be very tired! Don’t go, will regret! ️ ️”

Welcome to follow your wechat official account: Tao Li Bao Chun Personal blog: Leeyunt. Top