kubenetes安裝

master節點主要由四個模塊組成:node

  • APIServer   提供了資源操做的惟一入口,任何對資源進行增刪改查的操做都要交給APIServer處理後再提交給etcd。kubectl就是對api server的調用。
  • scheduler  負責資源的調度,按照預約的調度策略將Pod調度到相應的機器上;
  • controller manager    負責維護集羣的狀態,好比故障檢測、自動擴展、滾動更新等;
  • etcd   是一個高可用的kv存儲系統,Kubernetes使用它來存儲各個資源的狀態,從而實現了Restful的API。

node節點主要由三個模塊組成:git

  • Container runtime  容器運行環境,經常使用docker容器
  • kubelet  負責維護容器的生命週期,管理pods和pods上面的容器
  • kube-proxy 負責爲Service提供cluster內部的服務發現和負載均衡

master&slave: docker,kubectl,github

master : kubeadm initdocker

slave: kubeadm joinbootstrap

 

 master節點

初始化master節點api

# kubeadm init  --kubernetes-version=v1.14.3 --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/12 --ignore-preflight-errors=swap
[init] using Kubernetes version: v1.14.3
[preflight] running pre-flight checks
    [WARNING KubernetesVersion]: kubernetes version is greater than kubeadm version. Please consider to upgrade kubeadm. kubernetes version: beadm version: 1.11.x

[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 following as a regular user:

  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  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 the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

You can now join any number of machines by running the following on each node
as root:

  kubeadm join 172.17.8.128:6443 --token 825yrh.qe2kpku40dwcwusb --discovery-token-ca-cert-hash sha256:02b158edd568a75523cb12a1561b65937bcf146319484fd86f88e9

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

# kubectl get cs
網絡

# kubectl get nodes
NAME STATUS ROLES AGE VERSION
master01 NotReady master 164m v1.11.2     #nodes處於NotReady狀態,由於缺乏網絡組件app

 

部署網絡組件 flannel負載均衡

# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
podsecuritypolicy.policy/psp.flannel.unprivileged created
clusterrole.rbac.authorization.k8s.io/flannel created
clusterrolebinding.rbac.authorization.k8s.io/flannel created
serviceaccount/flannel created
configmap/kube-flannel-cfg created
daemonset.apps/kube-flannel-ds-amd64 created
daemonset.apps/kube-flannel-ds-arm64 created
daemonset.apps/kube-flannel-ds-arm created
daemonset.apps/kube-flannel-ds-ppc64le created
daemonset.apps/kube-flannel-ds-s390x created

 等待一下子ide

docker image ls    看到flannel鏡像下載下來 

 kubectl get pods  -n kube-system  查看pods運行在,

才說明flannel安裝成功

# kubectl get pods -n kube-system
NAME                               READY   STATUS    RESTARTS   AGE
coredns-8686dcc4fd-qg5jz           1/1     Running   0          4m33s
coredns-8686dcc4fd-vx64c           1/1     Running   0          4m33s
etcd-master01                      1/1     Running   0          3m46s
kube-apiserver-master01            1/1     Running   0          3m42s
kube-controller-manager-master01   1/1     Running   0          3m33s
kube-flannel-ds-amd64-5sbrx        1/1     Running   1          2m49s
kube-flannel-ds-amd64-wlr5x        1/1     Running   0          3m34s
kube-proxy-d2pzd                   1/1     Running   0          2m49s
kube-proxy-gpwkg                   1/1     Running   0          4m33s
kube-scheduler-master01            1/1     Running   0          3m49s  

再查看  kubectl get nodes  會看到已經ready

# kubectl get nodes
NAME            STATUS   ROLES    AGE     VERSION
master01        Ready    master   5m52s   v1.14.3

 

 

node節點

安裝組件

# yum install kubelet-1.14.3  kubeadm-1.14.3  kubectl-1.14.3 

加入集羣

# kubeadm join 172.17.8.128:6443 --token j1u40p.5is2liahibv1gwgk --discovery-token-ca-cert-hash sha256:51579863a2ff093f730c0552c13c44ea87e270064a7fc9ba5bac069ca47cf2cb [preflight] Running pre-flight checks
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml'
[kubelet-start] Downloading configuration for the kubelet from the "kubelet-config-1.14" ConfigMap in the kube-system namespace
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Activating the kubelet service
[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...

This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.

Run 'kubectl get nodes' on the control-plane to see this node join the cluster.

node加入集羣后 在master上面查看

[master01 ]# kubectl get nodes
NAME                                      STATUS   ROLES    AGE     VERSION
master01 Ready    master   10m     v1.14.3node01   Ready    <none>   8m18s   v1.14.3

 

 

 

報錯1:

啓動docker時報錯:Error starting daemon: Error initializing network controller: list bridge addresses failed: no available network

  解決:須要手動添加下docker0網橋:

brctl addbr docker0
ip addr add 172.17.0.1/16 dev docker0
ip link set dev docker0 up
systemctl restart docker

 

報錯2:初始化kubeadm時

[preflight] Some fatal errors occurred:
[ERROR ImagePull]: failed to pull image [k8s.gcr.io/kube-apiserver-amd64:v1.14.3]: exit status 1
[ERROR ImagePull]: failed to pull image [k8s.gcr.io/kube-controller-manager-amd64:v1.14.3]: exit status 1
[ERROR ImagePull]: failed to pull image [k8s.gcr.io/kube-scheduler-amd64:v1.14.3]: exit status 1
[ERROR ImagePull]: failed to pull image [k8s.gcr.io/kube-proxy-amd64:v1.14.3]: exit status 1
[ERROR ImagePull]: failed to pull image [k8s.gcr.io/pause:3.1]: exit status 1
[ERROR ImagePull]: failed to pull image [k8s.gcr.io/etcd-amd64:3.2.18]: exit status 1
[ERROR ImagePull]: failed to pull image [k8s.gcr.io/coredns:1.1.3]: exit status 1
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`

解決方法:
經過別的鏡像倉庫,先將鏡像下載下來而後再修改爲k8s.gcr.io對應的tag
docker pull mirrorgooglecontainers/kube-apiserver-amd64:v1.14.3
docker pull mirrorgooglecontainers/kube-controller-manager-amd64:v1.14.3
docker pull mirrorgooglecontainers/kube-scheduler-amd64:v1.14.3
docker pull mirrorgooglecontainers/kube-proxy-amd64:v1.14.3
docker pull mirrorgooglecontainers/pause:3.1
docker pull mirrorgooglecontainers/etcd-amd64:3.2.18
docker pull coredns/coredns:1.3.1

修改tag:
docker tag mirrorgooglecontainers/kube-apiserver-amd64:v1.14.3 k8s.gcr.io/kube-apiserver-amd64:v1.14.3
docker tag mirrorgooglecontainers/kube-controller-manager-amd64:v1.14.3 k8s.gcr.io/kube-controller-manager-amd64:v1.14.3
docker tag mirrorgooglecontainers/kube-scheduler-amd64:v1.14.3 k8s.gcr.io/kube-scheduler-amd64:v1.14.3
docker tag mirrorgooglecontainers/etcd-amd64:3.2.18 k8s.gcr.io/etcd-amd64:3.2.18
docker tag mirrorgooglecontainers/kube-proxy-amd64:v1.14.3 k8s.gcr.io/kube-proxy-amd64:v1.14.3
docker tag coredns/coredns:1.3.1 k8s.gcr.io/coredns:1.1.3
docker tag mirrorgooglecontainers/pause:3.1 k8s.gcr.io/pause:3.1

 

 

報錯3: node 執行 kubeadm join  加入集羣時報錯: 

        報錯1:configmaps "kubelet-config-1.11" is forbidden: User "system:bootstrap:wdchig" cannot get resource "configmaps" in API group "" in the namespacetem"

       緣由:版本問題,當前版本爲1.11.2 。須要升級kubelet和kubeadm。按照上面的安裝步驟來,安裝的時候指定版本便可。

 

  報錯2:couldn't validate the identity of the API Server: expected a 32 byte SHA-256 hash, found 29 bytes

  緣由:kubeadm init生成的token有效期只有1天

  解決方法:

  在master節點檢查token是否有效

  master #    kubeadm token list  查看

  master# kubeadm token create --print-join-command 生成新的token和命令。而後在node從新執行

 

 報錯4:  從新執行初始化的時候報錯:     error marking master: timed out waiting for the condition

解決:

# kubeadm reset -f && rm -rf /etc/kubernetes/

 清理集羣數據 而後再 kubeadm init --kubernetes-version=v1.14.3 --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/12 --ignore-preflight-errors=Swap

相關文章
相關標籤/搜索