docker安裝kubelet


安裝kubelet

准備條件 虛擬機、安裝centos、安裝docker

安裝docker (步驟一)

curl -fsSL get.docker.com -o get-docker.sh
vi get-docker.sh
sh get-docker.sh --mirror Aliyun
systemctl daemon-reload

啟動、重啟 關閉

systemctl start docker

systemctl restart docker

systemctl stop docker

安裝kubelet (步驟二)

設置配置文件 跟阿里鏡像倉庫

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

配置跟安裝

setenforce 0
# 將 SELinux 設置為 permissive 模式(相當於將其禁用)
sudo setenforce 0
sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

sudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes

啟動

設置開機自啟動

sudo systemctl enable --now kubelet

重啟
systemctl restart kubelet

關閉分區

臨時關閉
swapoff -a

集群搭建

設置主機名稱

hostnamectl set-hostname master

查看

hostname

准備步驟 修改master host信息 其他節點 不修改

  • 第一步
vim /etc/hosts

192.168.0.138 master
192.168.0.142 node1
192.168.0.143 node2

  • 第二步
    重啟服務器 使hosts生效
reboot now

或者

sysctl --system 

同步時間

yum install ntpdate -y

ntpdate time.windows.com

初始化master節點

kubeadm init \
--apiserver-advertise-address=192.168.0.142 \ # 本機ip 只需要修改這一個
--image-repository registry.aliyuncs.com/google_containers \
--pod-network-cidr=10.244.0.0/16

下載鏡像

這可能會出現一個問題 Get http://localhost:10248/healthz: dial tcp 127.0.0.1:10248: connect: connection refused.
解決方式

解決方法

[root@k8s-node2 ~]# vim /etc/docker/daemon.json

{
"exec-opts": ["native.cgroupdriver=systemd"],
}


重啟docker
[root@k8s-node2 ~]# systemctl restart docker

重置kubelet
[root@k8s-master ~]# kubeadm reset -f

設置后重新 初始化 完成

配置


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

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

報錯連接不上 修改hosts

vim /etc/hosts

添加
199.232.68.133 raw.githubusercontent.com

其他節點

mater操作完后,其他節點操作步驟一 步驟三 然后 復制 master 執行成功后的join
例子

# master需要執行的
 mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config
# master執行結束

Alternatively, if you are the root user, you can run:

  export KUBECONFIG=/etc/kubernetes/admin.conf

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/

Then you can join any number of worker nodes by running the following on each as root:

# 其他節點 執行以下語句
kubeadm join 192.168.0.138:6443 --token gsx0cs.zz0hi3m7dj4kl4rv \
	--discovery-token-ca-cert-hash sha256:5a0caffb4721abe446adebb9b62fd677c0a4923b4fee9fed39df4aacef1516ac 

牛刀小試

kubectl apply -f filename

查看pod
kubectl get pod

查看pod詳情
kubectl describe pod pod名稱

查看縮略信息
kubectl get pod -o wide

列出文件名
kubectl exec  mynginx ls /

登錄
kubectl exec -it mynginx /bin/bash

校時
kubectl cp /etc/localtime containerid:/etc/localtime

錯誤


error: unable to recognize "mynginx-deployment.yml": no matches for kind "Deployment" in version "extensions/v1beta1"

修改apiVersion

擴縮容


kubectl edit deployment mynginx-deployment


修改問價 重新apply -f

其他

重置kubeadm

# 重置kubeadm
kubeadm reset

查案日志

 journalctl -fu kubelet

錯誤 一

firewalld is active, please ensure ports [6443 10250] are open or your cluste r may not function correctly

開放端口

firewall-cmd --zone=public --add-port=6443/tcp --permanent && firewall-cmd --zone=public --add-port=10250/tcp --permanent && firewall-cmd --reload

錯誤二

 running with swap on is not supported. Please disable swap

關閉

swapoff -a

永久設置

編輯/etc/fstab文件,注釋掉swap行
vim /etc/fstab 

問題三

The connection to the server 192.168.0.138:6443 was refused - did you specify the right host or port?


免責聲明!

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



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