Kubernetes 學習筆記,記錄下來!💻🚀node
準備三臺CentOS 7.0+的機器,更改Hostname爲Master、node-0一、node-02:linux
節點 | IP地址 |
---|---|
Master | 10.211.55.7 |
node-01 | 10.211.55.8 |
node-02 | 10.211.55.9 |
我這裏新建立了三臺虛擬機: docker
vi /etc/hosts
複製代碼
添加以下這三行後保存退出。vim
10.211.55.7 Master
10.211.55.8 node-01
10.211.55.9 node-02
複製代碼
注意:如下命令,非root用戶須要sudo權限帶sudo 執行相關命令。 root用戶去掉sudo執行。
一、關閉防火牆:sudo systemctl stop firewalld.servicecentos
二、關閉開機啓動:sudo systemctl disable firewalld.serviceapi
查看防火牆狀態:firewall-cmd --statebash
查看是否開機啓動:systemctl is-enabled firewalld.service服務器
sudo setenforce 0
sudo vi /etc/selinux/config
#SELINUX修改成disabled
SELINUX=disabled
複製代碼
關閉系統的Swap命令以下:微信
swapoff -a
複製代碼
同時還須要修改/etc/fstab文件,註釋掉SWAP的自動掛載,防止機子重啓後swap啓用。 使用命令:網絡
vi /etc/fstab
複製代碼
註釋swap這一行後保存退出。
# /dev/mapper/centos-swap swap swap defaults 0 0
複製代碼
確認swap已經關閉,使用命令:
free -m
複製代碼
swap輸出爲0則說明已經關閉。
yum -y install epel-release
複製代碼
而後升級到最新版本:
yum update
複製代碼
開始安裝:(全部主機)
yum install -y etcd kubernetes-master ntp flannel
複製代碼
安裝了etcd 3.3.十一、flannel 0.7.一、kubernetes-master 1.5.2版本。
繼續安裝node:
yum install -y kubernetes-node ntp flannel docker
複製代碼
時間校對:(全部主機)
systemctl start ntpd
ntpdate ntp1.aliyun.com
hwclock -w
複製代碼
vim /etc/etcd/etcd.conf
複製代碼
修改成如下內容:
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"
複製代碼
查看是否修改:
grep -v '^#' /etc/etcd/etcd.conf
複製代碼
啓動etcd服務
systemctl start etcd
複製代碼
檢查etcd集羣狀態
etcdctl cluster-health
複製代碼
檢查etcd集羣成員列表,這裏只有一臺
etcdctl member list
複製代碼
vim /etc/etcd/etcd.conf
複製代碼
修改成如下內容:
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"
複製代碼
啓動etcd服務
systemctl start etcd
複製代碼
檢查etcd集羣狀態
etcdctl cluster-health
複製代碼
檢查etcd集羣成員列表
etcdctl member list
複製代碼
編輯etcd.conf文件:
vim /etc/etcd/etcd.conf
複製代碼
修改成如下內容:
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"
複製代碼
啓動etcd服務
systemctl start etcd
複製代碼
檢查etcd集羣狀態
etcdctl cluster-health
複製代碼
檢查etcd集羣成員列表
etcdctl member list
複製代碼
[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"
複製代碼
[root@Master ~]# grep -v '^#' /etc/kubernetes/apiserver
KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"
KUBE_ETCD_SERVERS="--etcd-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=""
複製代碼
[root@Master ~]# grep -v '^#' /etc/kubernetes/controller-manager
KUBE_CONTROLLER_MANAGER_ARGS=""
複製代碼
[root@Master ~]# grep -v '^#' /etc/kubernetes/scheduler
KUBE_SCHEDULER_ARGS="--address=0.0.0.0"
複製代碼
for i in kube-apiserver kube-controller-manager kube-scheduler;do systemctl restart $i; systemctl enable $i;done
複製代碼
[root@Master ~]# etcdctl set /atomic.io/network/config '{"Network": "172.16.0.0/16"}'
{"Network": "172.16.0.0/16"}
複製代碼
[root@node01 ~]# grep -v '^#' /etc/sysconfig/flanneld
FLANNEL_ETCD_ENDPOINTS="http://10.211.55.8:2379"
FLANNEL_ETCD_PREFIX="/atomic.io/network"
FLANNEL_OPTIONS=""
複製代碼
查看驗證網絡信息
[root@Master ~]# etcdctl get /atomic.io/network/config
{ "Network": "172.16.0.0/16" }
複製代碼
[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-24
複製代碼
[root@Master ~]# etcdctl get /atomic.io/network/subnets/172.16.6.0-24
{"PublicIP":"10.211.55.8"}
複製代碼
[root@Master ~]# etcdctl get /atomic.io/network/subnets/172.16.69.0-24
{"PublicIP":"10.211.55.9"}
複製代碼
[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"
複製代碼
[root@node01 ~]# grep -v '^#' /etc/kubernetes/proxy
KUBE_PROXY_ARGS="--bind=address=0.0.0.0"
複製代碼
[root@node01 ~]# grep -v '^#' /etc/kubernetes/kubelet
KUBELET_ADDRESS="--address=127.0.0.1"
KUBELET_HOSTNAME="--hostname-override=10.10.10.15"
KUBELET_API_SERVER="--api-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=""
複製代碼
for i in flanneld kube-proxy kubelet docker;do systemctl restart $i;systemctl enable $i;systemctl status $i ;done
複製代碼
node2與node1配置基本一致,除下面一處例外
[root@node2 ~]# vi /etc/kubernetes/kubelet
KUBELET_HOSTNAME="--hostname-override=10.211.55.9"
複製代碼
查看節點
[root@Master ~]# kubectl get nodes
NAME STATUS AGE
10.211.55.8 Ready 18h
10.211.55.9 Ready 13h
複製代碼
歡迎關注我的微信公衆號:桃李報春 我的博客:leeyunt.top