k8s 火力为王

本文档详述了在Ubuntu环境下搭建Kubernetes(k8s)集群的过程,包括环境配置、节点分配、软件安装、kubeadm初始化、网络插件选择(以Calico为例)以及Kubernetes Dashboard的安装和配置。通过这个过程,读者可以了解到如何从零开始建立一个基本的k8s集群。
摘要由CSDN通过智能技术生成

实验环境:
Desktop :客户端 ,NFS Storage # student , student #utility 工具 Dockerfile # 192.168.19.254 # 网关 此虚拟机一
定要开机 。
Master: K8S管理端 # 192.168.19.100
Node1: K8S节点1 #192.168.19.101
Node2: K8S节点2 #192.168.19.102
Ubuntu #考试系统
Desktop : NAT 上课必须开启 ,客户端 ,存储 账户和密码 student : student , root : root 
192.168.19.254
Master : K8S管理节点 账户和密码 student : student , root : root 
192.168.19.100
Node1: Work节点 账户和密码 student : student , root : root 
192.168.19.101
Node2: Work节点 账户和密码 student : student , root : root 
192.168.19.102
1.在所有节点master节点上部署k8s master
安装工具包:
student@master:~$ sudo apt-get update && sudo apt-get install -y ca-certificates curl softwareproperties-common apt-transport-https curl
添加阿里apt-key
student@master:~$ curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo aptkey add -
Ubuntu部署kubernetes
 分区 Ubuntu部署kubernetes 的第 1 页 
key add -
OK
student@master:~$ 
配置使用阿里kubernetes源:
sudo tee /etc/apt/sources.list.d/kubernetes.list <<EOF 
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
student@master:~$ sudo tee /etc/apt/sources.list.d/kubernetes.list <<EOF 
> deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
> EOF
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
student@master:~$ 
更新软件源:
student@master:~$ sudo apt-get update
Hit:1 http://mirrors.aliyun.com/ubuntu focal InRelease
Hit:2 http://mirrors.aliyun.com/ubuntu focal-security InRelease
Hit:3 http://mirrors.aliyun.com/ubuntu focal-updates InRelease 
Get:4 https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial InRelease [8993 B] 
Hit:5 http://mirrors.aliyun.com/ubuntu focal-proposed InRelease 
Hit:6 http://mirrors.aliyun.com/ubuntu focal-backports InRelease
Ign:7 https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial/main amd64 Packages
Get:7 https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial/main amd64 Packages [38.8 kB]
Fetched 47.8 kB in 2s (26.6 kB/s) 
Reading package lists... Done
student@master:~$ 
#通过kubeadm方式部署:
安装指定版本的K8S软件包:
student@master:/etc/apt/sources.list.d$ sudo apt install kubeadm=1.18.6-00 kubectl=1.18.6-00 
kubelet=1.18.6-00
master,node1,node2上安装kubelet, kubeadm, kubectl
student@master:~$ sudo apt-get install -y kubelet kubeadm kubectl
 分区 Ubuntu部署kubernetes 的第 2 页 
初始化master:
sudo kubeadm init --kubernetes-version=1.18.2 \
--apiserver-advertise-address=192.168.19.100 \
--image-repository registry.aliyuncs.com/google_containers \
--service-cidr=10.1.0.0/16 \
--pod-network-cidr=10.244.0.0/16
参数:
--kubernetes-version=1.18.2 : 指定安装 1.18.2 最新 1.18.2 
--apiserver-advertise-address=192.168.19.100 # master 
--image-repository registry.aliyuncs.com/google_containers # 安装时下载 阿里的镜像
--service-cidr=10.1.0.0/16 # svc的 网络 VIP # kubeproxy #ClusterIP
--pod-network-cidr=10.244.0.0/16 # pod网段 
student@master:~$ sudo kubeadm init --kubernetes-version=1.18.2 \
> --apiserver-advertise-address=192.168.19.100 \
> --image-repository registry.aliyuncs.com/google_containers \
> --service-cidr=10.1.0.0/16 \
> --pod-network-cidr=10.244.0.0/16
W0812 20:07:16.089865 3731 configset.go:202] WARNING: kubeadm cannot validate component 
configs for API groups [kubelet.config.k8s.io kubeproxy.config.k8s.io]
[init] Using Kubernetes version: v1.18.2
[WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The 
[preflight] Running pre-flight checks
 分区 Ubuntu部署kubernetes 的第 3 页 
[WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The 
recommended driver is "systemd". Please follow the guide at 
https://kubernetes.io/docs/setup/cri/
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadmflags.env"
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Starting the kubelet
[certs] Using certificateDir folder "/etc/kubernetes/pki"
[certs] Generating "ca" certificate and key
[certs] Generating "apiserver" certificate and key
[certs] apiserver serving cert is signed for DNS names [master kubernetes kubernetes.defa
Your Kubernetes control-plane 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/
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join 192.168.19.100:6443 --token la82lq.j25bot0eopia3knp \
 --discovery-token-ca-cert-hash 
sha256:221335f0da68ce2395509d37f1abf5805b73a999ff4233f6c49d633aeb8fd63d 
student@master:~$ 
student@master:~$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED 
STATUS PORTS NAMES
39d01acb2e6f bc9c328f379c "/usr/local/bin/kube…" 5 minutes ago 
Up 5 minutes k8s_kube-proxy_kube-proxy-64fb4_kube-system_2f7fe8d4-
cbf8-423b-bc89-ade5014a310b_0
0eddb2c25fa9 registry.aliyuncs.com/google_containers/pause:3.2 "/pause" 5 
minutes ago Up 5 minutes k8s_POD_kube-proxy-64fb4_kube-system_2f7fe8d4-
cbf8-423b-bc89-ade5014a310b_0
81387b2c2f34 d4ca8726196c "etcd --advertise-cl…" 6 minutes ago 
Up 6 minutes k8s_etcd_etcd-master_kube-system_
754d7b14ce170dd6f2ea9b723326e8c5_0
 分区 Ubuntu部署kubernetes 的第 4 页 
754d7b14ce170dd6f2ea9b723326e8c5_0
d61b96c18a3e cbdc8369d8b1 "kube-scheduler --au…" 6 minutes ago 
Up 6 minutes k8s_kube-scheduler_kube-scheduler-master_kube-system_
670a3f9629c937daf0c4a0b80213c1f8_0
596ae33f57ea 09d665d529d0 "kube-controller-man…" 6 minutes ago 
Up 6 minutes k8s_kube-controller-manager_kube-controller-managermaster_kube-system_bf4923690b64f1f087e9dea15973941f_0
b6d5b5959251 1b74e93ece2f "kube-apiserver --ad…" 6 minutes ago 
Up 6 minutes k8s_kube-apiserver_kube-apiserver-master_kubesystem_fa44272de38ca0bd51456a31b1356cbe_0
c21595505346 registry.aliyuncs.com/google_containers/pause:3.2 "/pause" 6 
minutes ago Up 6 minutes k8s_POD_kube-scheduler-master_kube-system_
670a3f9629c937daf0c4a0b80213c1f8_0
a3d04c1d5df5 registry.aliyuncs.com/google_containers/pause:3.2 "/pause" 6 
minutes ago Up 6 minutes k8s_POD_kube-controller-manager-master_kubesystem_bf4923690b64f1f087e9dea15973941f_0
705e270d20a7 registry.aliyuncs.com/google_containers/pause:3.2 "/pause" 6 
minutes ago Up 6 minutes k8s_POD_kube-apiserver-master_kubesystem_fa44272de38ca0bd51456a31b1356cbe_0
38817872b00b registry.aliyuncs.com/google_containers/pause:3.2 "/pause" 6 
minutes ago Up 6 minutes k8s_POD_etcd-master_kube-system_
754d7b14ce170dd6f2ea9b723326e8c5_0
student@master:~$ 
kubelet:# 管理docker服务 ,k8s中使用kubelet 管理docker api 在master ,node节点上 都要安装
kubectl: 管理命令行工具
master: 单节点
kubelet:# 管理docker服务 ,k8s中使用kubelet 管理docker api 在master ,node节点上 都要安装 # 本地的服务 操作系
统管理 静态POD,所有节点都要运行。
api-server: api服务器 
scheduler:调度器
etcd: 数据库,(pod部署)保存所有数据 分存式数据 # kubernetes HA 使用, 虚拟机部署etcd
kubeproxy: haproxy 实现 VIP ,svc(service) ---- > pod ip 流量分发
kubectl : 管理命令行工具
node:
kubelet: 管理docker服务 ,k8s中使用kubelet 管理docker api # 本地的服务 操作系统管理
kubeproxy: haproxy 实现 VIP ,svc(service) ---- > pod ip 流量分发
kubectl : 管理命令行工具
 分区 Ubuntu部署kubernetes 的第 5 页 
配置身份认证:
student@master:~$ mkdir -p $HOME/.kube
student@master:~$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
student@master:~$ sudo chown $(id -u):$(id -g) $HOME/.kube/config
student@master:~$ 
安装calico网络插件支持 网络策略: flannel 不建议使用 # 不支持 网络策略
student@master:~$ wget https://docs.projectcalico.org/v3.20/manifests/calico.yaml
--2020-08-12 20:11:31-- https://docs.projectcalico.org/v3.20/manifests/calico.yaml
Resolving docs.projectcalico.org (docs.projectcalico.org)... 178.128.17.49, 157.230.35.153, 
2400:61

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值