花门楼前见秋草,岂能贫贱相看老。这篇文章主要讲述mac上kubeadmin安装k8s(完整)相关的知识,希望能为你提供帮助。
1.安装virtualBox这个自行百度,安装好后,配置一下
这里我一点开,就这样,没有修改。
2.vagrant安装虚拟机2.1.安装vagrant
dz0400819@MacBook-Pro ~ brew install vagrant
2.2.vagrant创建虚拟机
这里安装的是ubuntu20.04,如果想要其他版本,可以到https://app.vagrantup.com/ubuntu这里找
创建虚拟机
~/Desktop/docker/host2 vagrant init ubuntu/focal64
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
启动虚拟机
~/Desktop/docker/host2 vagrant up
进入虚拟机
~/Desktop/docker/host2 vagrant ssh
2.3.内存至少为2G,少了报错
3.安装docker3.1.安装docker
安装docker
root@ubuntu-focal:~# curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
3.2.查看docker的cgroup driver
Cgroup Driver: cgroupfs
root@ubuntu-focal:~# docker info
Client:
Context:default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Docker Buildx (Docker Inc., v0.7.1-docker)
scan: Docker Scan (Docker Inc., v0.12.0)
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 20.10.12
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
runc version: v1.0.2-0-g52b36a2
init version: de40ad0
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 5.4.0-96-generic
Operating System: Ubuntu 20.04.3 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.937GiB
Name: ubuntu-focal
ID: QK46:H3FX:EQIZ:QGHG:OLKZ:T3ID:QA65:LXNC:BRXR:HVUK:RCOQ:LDLO
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: No swap limit support
3.3修改docker的cgroup driver
修改为systemd,要和kubelet的cgroup driver保持一致,不一致kubelet启动不了。kubelet的1.22.2版本的cgroup driver是systemd,哈哈,因为坑我已经踩过一遍了。
root@ubuntu-focal:~# vim /etc/docker/daemon.json
root@ubuntu-focal:~# cat /etc/docker/daemon.json
"exec-opts": ["native.cgroupdriver=systemd"]
3.4启动docker并查看状态
启动后最好在docker info查看下cgroup driver是不是systemd
root@ubuntu-focal:~# service docker start
root@ubuntu-focal:~# service docker status
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service;
enabled;
vendor preset: enabled)
Active: active (running) since Sat 2022-01-29 11:27:54 UTC;
3min 28s ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 721 (dockerd)
Tasks: 8
Memory: 107.7M
CGroup: /system.slice/docker.service
└─721 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Jan 29 11:27:53 ubuntu-focal dockerd[721]: time="2022-01-29T11:27:53.271733866Z" level=warning msg="Your kernel does not support CPU realtime scheduler"
Jan 29 11:27:53 ubuntu-focal dockerd[721]: time="2022-01-29T11:27:53.271869462Z" level=warning msg="Your kernel does not support cgroup blkio weight"
Jan 29 11:27:53 ubuntu-focal dockerd[721]: time="2022-01-29T11:27:53.272000492Z" level=warning msg="Your kernel does not support cgroup blkio weight_device"
Jan 29 11:27:53 ubuntu-focal dockerd[721]: time="2022-01-29T11:27:53.277560109Z" level=info msg="Loading containers: start."
Jan 29 11:27:53 ubuntu-focal dockerd[721]: time="2022-01-29T11:27:53.948408290Z" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be>
Jan 29 11:27:54 ubuntu-focal dockerd[721]: time="2022-01-29T11:27:54.139527485Z" level=info msg="Loading containers: done."
Jan 29 11:27:54 ubuntu-focal dockerd[721]: time="2022-01-29T11:27:54.413437051Z" level=info msg="Docker daemon" commit=459d0df graphdriver(s)=overlay2 version=20.10.12
Jan 29 11:27:54 ubuntu-focal dockerd[721]: time="2022-01-29T11:27:54.415677294Z" level=info msg="Daemon has completed initialization"
Jan 29 11:27:54 ubuntu-focal systemd[1]: Started Docker Application Container Engine.
Jan 29 11:27:54 ubuntu-focal dockerd[721]: time="2022-01-29T11:27:54.503854906Z" level=info msg="API listen on /run/docker.sock"
4.Letting iptables see bridged traffic$ cat <
<
EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF
$ cat <
<
EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
$ sudo sysctl --system
5.安装相关软件5.1安装net-tools
因为要查看虚拟机的网络
root@ubuntu-focal:~# ifconfig
Command ifconfig not found, but can be installed with:
apt install net-tools
root@ubuntu-focal:~# apt-get update
root@ubuntu-focal:~# apt install net-tools
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
net-tools
0 upgraded, 1 newly installed, 0 to remove and 4 not upgraded.
Need to get 196 kB of archives.
After this operation, 864 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu focal/main amd64 net-tools amd64 1.60+git20180626.aebd88e-1ubuntu1 [196 kB]
Fetched 196 kB in 3s (61.0 kB/s)
Selecting previously unselected package net-tools.
(Reading database ... 63485 files and directories currently installed.)
Preparing to unpack .../net-tools_1.60+git20180626.aebd88e-1ubuntu1_amd64.deb ...
Unpacking net-tools (1.60+git20180626.aebd88e-1ubuntu1) ...
Setting up net-tools (1.60+git20180626.aebd88e-1ubuntu1) ...
Processing triggers for man-db (2.9.1-1) ...
5.2Update the apt package index and install packages needed to use the Kubernetes apt repository:
root@ubuntu-focal:~# apt-get update
Hit:1 https://mirrors.aliyun.com/docker-ce/linux/ubuntu focal InRelease
Hit:2 http://security.ubuntu.com/ubuntu focal-security InRelease
Hit:3 http://archive.ubuntu.com/ubuntu focal InRelease
Hit:4 http://archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:5 http://archive.ubuntu.com/ubuntu focal-backports InRelease
Reading package lists... Done
root@ubuntu-focal:~# apt-get install -y apt-transport-https ca-certificates curl
Reading package lists... Done
Building dependency tree
Reading state information... Done
ca-certificates is already the newest version (20210119~20.04.2).
curl is already the newest version (7.68.0-1ubuntu2.7).
apt-transport-https is already the newest version (2.0.6).
0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.
5.3Install kubeadm
root@ubuntu-focal:~# curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add -
OK
5.4Add the Kubernetes apt repository
$ sudo tee /etc/apt/sources.list.d/kubernetes.list <
<
-EOF
deb https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial main
EOF
5.5安装kubelet
更新apt package index更新apt package index
root@ubuntu-focal:~# apt-get update
查看kubelet有哪些版本root@ubuntu-focal:~# apt-cache policy kubelet
安装kubelet 1.22.2【mac上kubeadmin安装k8s(完整)】因为k8s集群就是安装的这个版本,版本要相同,都则会报错
root@ubuntu-focal:~# apt-get install kubelet=1.22.2-00
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
conntrack ebtables kubernetes-cni socat
Suggested packages:
nftables
The following NEW packages will be installed:
conntrack ebtables kubelet kubernetes-cni socat
0 upgraded, 5 newly installed, 0 to remove and 4 not upgraded.
Need to get 47.3 MB of archives.
After this operation, 227 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial/main amd64 kubernetes-cni amd64 0.8.7-00 [25.0 MB]
Get:2 http://archive.ubuntu.com/ubuntu focal/main amd64 conntrack amd64 1:1.4.5-2 [30.3 kB]
Get:3 http://archive.ubuntu.com/ubuntu focal/main amd64 ebtables amd64 2.0.11-3build1 [80.3 kB]
Get:4 http://archive.ubuntu.com/ubuntu focal/main amd64 socat amd64 1.7.3.3-2 [323 kB]
Get:5 https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial/main amd64 kubelet amd64 1.22.2-00 [21.9 MB]
Fetched 47.3 MB in 6s (7442 kB/s)
Selecting previously unselected package conntrack.
(Reading database ... 63534 files and directories currently installed.)
Preparing to unpack .../conntrack_1%3a1.4.5-2_amd64.deb ...
Unpacking conntrack (1:1.4.5-2) ...
Selecting previously unselected package ebtables.
Preparing to unpack .../ebtables_2.0.11-3build1_amd64.deb ...
Unpacking ebtables (2.0.11-3build1) ...
Selecting previously unselected package kubernetes-cni.
Preparing to unpack .../kubernetes-cni_0.8.7-00_amd64.deb ...
Unpacking kubernetes-cni (0.8.7-00) ...
Selecting previously unselected package socat.
Preparing to unpack .../socat_1.7.3.3-2_amd64.deb ...
Unpacking socat (1.7.3.3-2) ...
Selecting previously unselected package kubelet.
Preparing to unpack .../kubelet_1.22.2-00_amd64.deb ...
Unpacking kubelet (1.22.2-00) ...
Setting up conntrack (1:1.4.5-2) ...
Setting up ebtables (2.0.11-3build1) ...
Setting up socat (1.7.3.3-2) ...
Setting up kubernetes-cni (0.8.7-00) ...
Setting up kubelet (1.22.2-00) ...
Created symlink /etc/systemd/system/multi-user.target.wants/kubelet.service → /lib/systemd/system/kubelet.service.
Processing triggers for man-db (2.9.1-1) ...
安装固定版本的kubeadm 和kubectlroot@ubuntu-focal:~# apt-get install -y kubeadm=1.22.2-00 kubectl=1.22.2-00
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
cri-tools
The following NEW packages will be installed:
cri-tools kubeadm kubectl
0 upgraded, 3 newly installed, 0 to remove and 5 not upgraded.
Need to get 28.9 MB of archives.
After this operation, 123 MB of additional disk space will be used.
Get:1 https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial/main amd64 cri-tools amd64 1.19.0-00 [11.2 MB]
Get:2 https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial/main amd64 kubectl amd64 1.22.2-00 [9038 kB]
Get:3 https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial/main amd64 kubeadm amd64 1.22.2-00 [8718 kB]
Fetched 28.9 MB in 4s (7822 kB/s)
Selecting previously unselected package cri-tools.
(Reading database ... 63622 files and directories currently installed.)
Preparing to unpack .../cri-tools_1.19.0-00_amd64.deb ...
Unpacking cri-tools (1.19.0-00) ...
Selecting previously unselected package kubectl.
Preparing to unpack .../kubectl_1.22.2-00_amd64.deb ...
Unpacking kubectl (1.22.2-00) ...
Selecting previously unselected package kubeadm.
Preparing to unpack .../kubeadm_1.22.2-00_amd64.deb ...
Unpacking kubeadm (1.22.2-00) ...
Setting up kubectl (1.22.2-00) ...
Setting up cri-tools (1.19.0-00) ...
Setting up kubeadm (1.22.2-00) ...
apt-mark holdroot@ubuntu-focal:~# apt-mark hold kubelet kubeadm kubectl
kubelet was already set on hold.
kubeadm set on hold.
kubectl set on hold.
5.6kubeadm init
查看虚拟机IP:10.0.2.15root@ubuntu-focal:~# ifconfig
docker0: flags=4099<
UP,BROADCAST,MULTICAST>
mtu 1500
inet 172.17.0.1netmask 255.255.0.0broadcast 172.17.255.255
ether 02:42:73:64:74:d0txqueuelen 0(Ethernet)
RX packets 0bytes 0 (0.0 B)
RX errors 0dropped 0overruns 0frame 0
TX packets 0bytes 0 (0.0 B)
TX errors 0dropped 0 overruns 0carrier 0collisions 0
enp0s3: flags=4163<
UP,BROADCAST,RUNNING,MULTICAST>
mtu 1500
inet 10.0.2.15netmask 255.255.255.0broadcast 10.0.2.255
inet6 fe80::cd:1cff:fe36:98prefixlen 64scopeid 0x20<
link>
ether 02:cd:1c:36:00:98txqueuelen 1000(Ethernet)
RX packets 93667bytes 134751544 (134.7 MB)
RX errors 0dropped 0overruns 0frame 0
TX packets 22209bytes 1469134 (1.4 MB)
TX errors 0dropped 0 overruns 0carrier 0collisions 0
lo: flags=73<
UP,LOOPBACK,RUNNING>
mtu 65536
inet 127.0.0.1netmask 255.0.0.0
inet6 ::1prefixlen 128scopeid 0x10<
host>
looptxqueuelen 1000(Local Loopback)
RX packets 140bytes 16230 (16.2 KB)
RX errors 0dropped 0overruns 0frame 0
TX packets 140bytes 16230 (16.2 KB)
TX errors 0dropped 0 overruns 0carrier
推荐阅读
- redis 哨兵模式 sentinel
- powershell 向内部证书颁发机构申请证书
- k8s-apiServer认证
- 回首图扑软件 2021,展望未来
- 如何判断NSMutableDictionary是否有某个key
- 8中Linux查看ip地址的方法
- 华为海思芯片如果很好,为什么手机大量使用别人的芯片
- Redis5.0集群安装配置
- 打磨TF卡叠加SIM的注意问题