第一章-KS8初體驗 安裝部署


一 配置yum源

[root@Centos-node4 ~]# cd /etc/yum.repos.d/
[root@Centos-node4 yum.repos.d]# wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
https://mirrors.aliyun.com/
[root@Centos-node4 yum.repos.d]# cat kubernetes.repo 
[kubernetes]
name=Kubernetes Repo
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
enabled=1

二 安裝

配置docker
[root@Centos-node4 ~]# yum install docker-ce kubelet kubeadm kubectl
#配置代理
[root@Centos-node4 ~]# mkdir -p /etc/systemd/system/docker.service.d
[root@Centos-node4 ~]# touch /etc/systemd/system/docker.service.d/http-proxy.conf
[root@Centos-node4 ~]# echo -e '[Service]\nEnvironment="HTTP_PROXY=http://www.ik8s.io:10080"' > /etc/systemd/system/docker.service.d/http-proxy.conf
[root@Centos-node4 ~]# docker info | grep -i proxy
HTTP Proxy: http://www.ik8s.io:10080
[root@Centos-node4 ~]# systemctl daemon-reload
[root@Centos-node4 ~]# systemctl restart docker
[root@Centos-node4 ~]# systemctl enable docker
[root@Centos-node4 ~]# systemctl enable kubelet.service 
#kubelet
[root@Centos-node4 ~]# rpm -ql kubelet
/etc/kubernetes/manifests         #清單目錄
/etc/sysconfig/kubelet                #配置文件
/etc/systemd/system/kubelet.service 
/usr/bin/kubelet
[root@Centos-node4 ~]# vim /etc/sysconfig/kubelet 
KUBELET_EXTRA_ARGS="--fail-swap-on=false"
rsion=v1.11.1 --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/12 --ignore-preflight-errors=Swap
#成功后顯示如下
[bootstraptoken] creating the "cluster-info" ConfigM
[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxy

Your Kubernetes master has initialized successfully!

To start using your cluster, you need to run the fol

  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of
  https://kubernetes.io/docs/concepts/cluster-admini

You can now join any number of machines by running t
as root:

  kubeadm join 192.168.10.140:6443 --token xcblqn.8
#安裝后操作
保存輸出:
  kubeadm join 192.168.10.140:6443 --token xcblqn.8gdt55d371aqfz00 --discovery-token-ca-cert-hash sha256:112d1a831a2636539b4a3c5a090d8d1b48975c6dfef8dd3a0a9f870b90a6f321
[root@Centos-node4 ~]# ss -lnt | grep 6443
LISTEN     0      128         :::6443                    :::*   

[root@Centos-node4 ~]# mkdir -p $HOME/.kube
[root@Centos-node4 ~]# cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

#查看組件信息

[root@Centos-node4 ~]# kubectl get componentstatus  #簡寫kubectl get cs
NAME STATUS MESSAGE ERROR
scheduler Healthy ok
controller-manager Healthy ok
etcd-0 Healthy {"health": "true"}

#查看節點信息

[root@Centos-node4 ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
centos-node4 NotReady master 53m v1.11.2

master部署flannel

GitHub地址:https://github.com/coreos/flannel

[root@Centos-node4 ~]# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
clusterrole.rbac.authorization.k8s.io/flannel created
clusterrolebinding.rbac.authorization.k8s.io/flannel created
serviceaccount/flannel created
configmap/kube-flannel-cfg created
daemonset.extensions/kube-flannel-ds-amd64 created
daemonset.extensions/kube-flannel-ds-arm64 created
daemonset.extensions/kube-flannel-ds-arm created
daemonset.extensions/kube-flannel-ds-ppc64le created
daemonset.extensions/kube-flannel-ds-s390x created
[root@Centos-node4 ~]# kubectl get nodes
NAME           STATUS    ROLES     AGE       VERSION
centos-node4   Ready     master    59m       v1.11.2
[root@Centos-node4 ~]# kubectl get pods -n kube-system
NAME                                   READY     STATUS    RESTARTS   AGE
coredns-78fcdf6894-4tsmh               1/1       Running   0          59m
coredns-78fcdf6894-n8795               1/1       Running   0          59m
etcd-centos-node4                      1/1       Running   0          58m
kube-apiserver-centos-node4            1/1       Running   0          58m
kube-controller-manager-centos-node4   1/1       Running   0          58m
kube-flannel-ds-amd64-dxpqv            1/1       Running   0          1m
kube-proxy-8v6rd                       1/1       Running   0          59m
kube-scheduler-centos-node4            1/1       Running   0          58m
#查看名稱空間
[root@Centos-node4 ~]# kubectl get ns
NAME          STATUS    AGE
default       Active    1h
kube-public   Active    1h
kube-system   Active    1h

Node節點配置加入master

yum源同master一樣

配置docker反向代理
mkdir -p /etc/systemd/system/docker.service.d
touch /etc/systemd/system/docker.service.d/http-proxy.conf
echo -e '[Service]\nEnvironment="HTTP_PROXY=http://www.ik8s.io:10080"' > /etc/systemd/system/docker.service.d/http-proxy.conf
systemctl daemon-reload
systemctl restart docker
#設置開機自啟
[root@Centos-node5 ~]# systemctl enable docker kubelet
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/kubelet.service to /etc/systemd/system/kubelet.service.

節點加入

[root@Centos-node5 ~]# cat >> /etc/sysctl.conf <<EOF
  net.bridge.bridge-nf-call-ip6tables = 1
  net.bridge.bridge-nf-call-iptables = 1
  net.bridge.bridge-nf-call-arptables = 1
EOF
[root@Centos-node5 ~]# sysctl -p /etc/sysctl.conf
[root@Centos-node5 ~]# kubeadm join 192.168.10.140:6443 --token xcblqn.8gdt55d371aqfz00 --discovery-token-ca-cert-hash sha256:112d1a831a2636539b4a3c5a090d8d1b48975c6dfef8dd3a0a9f870b90a6f321 --ignore-preflight-errors=Swap

 主節點驗證

[root@Centos-node4 ~]# kubectl get nodes
NAME           STATUS    ROLES     AGE       VERSION
centos-node4   Ready     master    2h        v1.11.2
centos-node5   Ready     <none>    42m       v1.11.2
centos-node6   Ready     <none>    8m        v1.11.2
[root@Centos-node4 ~]# kubectl get pods -n kube-system -o wide
NAME                                   READY     STATUS    RESTARTS   AGE       IP               NODE
coredns-78fcdf6894-4tsmh               1/1       Running   0          2h        10.244.0.2       centos-node4
coredns-78fcdf6894-n8795               1/1       Running   0          2h        10.244.0.3       centos-node4
etcd-centos-node4                      1/1       Running   0          2h        192.168.10.140   centos-node4
kube-apiserver-centos-node4            1/1       Running   0          2h        192.168.10.140   centos-node4
kube-controller-manager-centos-node4   1/1       Running   0          2h        192.168.10.140   centos-node4
kube-flannel-ds-amd64-dxpqv            1/1       Running   0          1h        192.168.10.140   centos-node4
kube-flannel-ds-amd64-rn292            1/1       Running   0          10m       192.168.10.142   centos-node6
kube-flannel-ds-amd64-xl8n5            1/1       Running   0          43m       192.168.10.141   centos-node5
kube-proxy-4nfv8                       1/1       Running   0          43m       192.168.10.141   centos-node5
kube-proxy-8v6rd                       1/1       Running   0          2h        192.168.10.140   centos-node4
kube-proxy-9lp7m                       1/1       Running   0          10m       192.168.10.142   centos-node6
kube-scheduler-centos-node4            1/1       Running   0          2h        192.168.10.140   centos-node4

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM