k8s node node deployment

Docker engine deployment

Install docker on node1 and node2

1. yum install docker

yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install -y docker-ce
systemctl start docker 

2. Refer to Alibaba Cloud to configure mirroring to speed up restart

systemctl daemon-reload 
systemctl restart docker 

flannel network configuration

1. Write the allocated subnet segment to ETCD for use by flannel

[root@master ssl]# ls
ca-key.pem  ca.pem  server-key.pem  server.pem
[root@master ssl]# /opt/etcd/bin/etcdctl --ca-file=ca.pem --cert-file=server.pem --key-file=server-key.pem --endpoints="https://192.168.176.181:2379,https://192.168.176.182:2379,https://192.168.176.183:2379" set /coreos.com/network/config '{ "Network": "172.17.0.0/16", "Backend": {"Type": "vxlan"}}'
返回内容
{ "Network": "172.17.0.0/16", "Backend": {"Type": "vxlan"}}

View the written information
Insert picture description here

2.Node node configuration flannel network

①Copy to all node nodes (only need to be deployed on node nodes)
Insert picture description here

tar xf flannel-v0.10.0-linux-amd64.tar.gz

②Create k8s working directory
Insert picture description here
[root@node1 ~]# mv mk-docker-opts.sh flanneld /opt/kubernetes/bin/

③ vim flannel.sh

#!/bin/bash

ETCD_ENDPOINTS=${1:-"http://127.0.0.1:2379"}

cat <<EOF >/opt/kubernetes/cfg/flanneld

FLANNEL_OPTIONS="--etcd-endpoints=${ETCD_ENDPOINTS} \
-etcd-cafile=/opt/etcd/ssl/ca.pem \
-etcd-certfile=/opt/etcd/ssl/server.pem \
-etcd-keyfile=/opt/etcd/ssl/server-key.pem"

EOF

cat <<EOF >/usr/lib/systemd/system/flanneld.service
[Unit]
Description=Flanneld overlay address etcd agent
After=network-online.target network.target
Before=docker.service

[Service]
Type=notify
EnvironmentFile=/opt/kubernetes/cfg/flanneld
ExecStart=/opt/kubernetes/bin/flanneld --ip-masq \$FLANNEL_OPTIONS
ExecStartPost=/opt/kubernetes/bin/mk-docker-opts.sh -k DOCKER_NETWORK_OPTIONS -d /run/flannel/subnet.env
Restart=on-failure

[Install]
WantedBy=multi-user.target

EOF

systemctl daemon-reload
systemctl enable flanneld
systemctl restart flanneld

④Execute the script

bash flannel.sh https://192.168.176.181:2379,https://192.168.176.182:2379,https://192.168.176.183:2379

Docker docking with flannel

Edit docker configuration file

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

Insert picture description here
Check the docke0 IP address (before the restart takes effect )
Insert picture description here
restart to take effect

systemctl daemon-reload
systemctl restart docker

Insert picture description here
node2 node performs the same operation

test

Run the container '

[root@node1 ~]#  docker run -it centos:7 /bin/bash

Insert picture description here

Insert picture description here

The container on the node1 node ping the container on the node2 node
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_50345511/article/details/114983837