ubuntu20.04使用kubeadm安装kubernetes1.23.4
cat >> /etc/hosts <
192.168.85.132 k8s-master
EOF
cat >> /etc/hosts <
192.168.85.133 k8s-node1
EOF
cat <
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
1、关闭swap
swapoff -a
vi /etc/fstab
2、配置系统参数
cat <
br_netfilter
EOF
cat <
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
更新apt包索引并安装使用Kubernetes apt库所需的包
sudo sysctl –system
sudo apt-get install -y apt-transport-https ca-certificates curl
二、安装docker
安装docker
apt install docker.io
配置docker cgroupdriver为systemd
vi /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"]
}
systemctl daemon-reload
systemctl restart docker
三、安装k8s
安装k8s
1、安装kubeadm
sudo curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add —
2、添加kubernetes镜像仓库
sudo tee /etc/apt/sources.list.d/kubernetes.list <<-‘EOF’
deb https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial main
EOF
3、安装kubelet, kubeadm and kubectl
列出所有版本
apt list kubeadm
用这个安装指定版本
apt install kubeadm=1.23.4-00 kubelet=1.23.4-00 kubectl=1.23.4-00 -y –allow-downgrades
这个是降版本–allow-downgrades
apt install kubectl=1.23.4-00 -y –allow-downgrades
4、初始化
kubeadm init
–image-repository registry.aliyuncs.com/google_containers
–kubernetes-version v1.23.4
–pod-network-cidr=10.10.0.0/16
–apiserver-advertise-address=192.168.85.132
或
kubeadm init \
–image-repository registry.aliyuncs.com/google_containers \
–kubernetes-version v1.23.4 \
–pod-network-cidr=10.10.0.0/16 \
–apiserver-advertise-address=192.168.111.116
5、配置kubeconfig
(初始化成功后)配置kubeconfig
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
6、node节点加入master
kubeadm join 192.168.85.132:6443 –token p3fphf.l6zj73eko03dkdcf
–discovery-token-ca-cert-hash sha256:e34a26875c83f90c0aeab1b8259750bc36584a7239a969cedf1ca4ad51c40a04
7、查看nodes
kubectl get nodes
8、安装网络组件calico(在主节点跑)
kubectl create -f https://docs.projectcalico.org/v3.21/manifests/calico.yaml
或
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl create -f https://docs.projectcalico.org/manifests/tigera-operator.yaml
wget https://docs.projectcalico.org/manifests/custom-resources.yaml
vim custom-resources.yaml
改为初始化的地址
安装
kubectl create -f custom-resources.yaml
查看所有的是否都是Running
kubectl get pod -A
9、安装 Kuboard v3
kubectl apply -f https://addons.kuboard.cn/kuboard/kuboard-v3.yaml
访问 Kuboard
在浏览器中打开链接 http://your-node-ip-address:30080
输入初始用户名和密码,并登录
用户名: admin
密码: Kuboard123
教程:https://www.kuboard.cn/install/v3/install-in-k8s.html#%E5%AE%89%E8%A3%85-2
安装Kuboard v2
kubectl apply -f https://kuboard.cn/install-script/kuboard.yaml
kubectl apply -f https://addons.kuboard.cn/metrics-server/0.3.7/metrics-server.yaml
查看 Kuboard 运行状态:
kubectl get pods -l k8s.kuboard.cn/name=kuboard -n kube-system
访问Kuboard
http://任意一个Worker节点的IP地址:32567/
获取Token
如果您参考 www.kuboard.cn 提供的文档安装 Kuberenetes,可在第一个 Master 节点上执行此命令
echo $(kubectl -n kube-system get secret $(kubectl -n kube-system get secret | grep ^kuboard-user | awk ‘{print $1}’) -o go-template='{{.data.token}}’ | base64 -d)
拿到Token登录就成功了。
以下是之前记录的
kubeadm list images列出所需的镜像
k8s.gcr.io/kube-apiserver:v1.23.4
k8s.gcr.io/kube-controller-manager:v1.23.4
k8s.gcr.io/kube-scheduler:v1.23.4
k8s.gcr.io/kube-proxy:v1.23.4
k8s.gcr.io/pause:3.6
k8s.gcr.io/etcd:3.5.1-0
k8s.gcr.io/coredns/coredns:v1.8.6
token
eyJhbGciOiJSUzI1NiIsImtpZCI6IkQ2MjBBR0ozX3VUTm5QeXVRSndIQmIwN3JWRVRPMTgtOFYyaTk2a2U1aXcifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJrdWJvYXJkLXVzZXItdG9rZW4tbHY5NHAiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoia3Vib2FyZC11c2VyIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiODNlODMyOGItNTdmYS00M2ExLTg4ZjItNzg0NmNkMjYzNDc5Iiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmt1Ym9hcmQtdXNlciJ9.MV3t3MAkVXVnJIo8V86gfW2Z2MdONNhmrOzUU-DQMekdPHJhnVH9qNsMjUhnu2OgrT06GtDXlYjxg3FSM86iXbZfY57rZ1AHoEoS_pLSrrRpW9crLXN4iBAirUgeXyYvAtqWeHb00Wtu0VlX9GZhDRQmiyTGmM-EGjpRfMYPgGutKarzy9kwTAnRCIngvhnKLaGfEenG-Rc2iYAaQcqrOoKnjtHHpMjwJH_X5pqVX1-zdV_0DyvPQiNOQyXBrkxQ29YbDMIkP9mE4X2yxrO0HR8OEXT5XYV9xgzKUhDy-F5AN9pCRcQre9ZM6YVVa2X2eLfdkta5hwrwBt3PgSYLjA
以下只是验证
验证是安装k8s是否成功
①命令式对象管理
运行一个nginx容器
kubectl run pod –image=nginx:1.22.0-alpine -n liuzc –port=78
创建一个nginx的控制器
kubectl create deployment nginx2 –image=nginx:1.22.0-alpine
暴露容器端口
kubectl expose deployment nginx2 –port=80 –type=NodePort
查看
kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 443/TCP 19h
nginx2 NodePort 10.102.227.181 80:30877/TCP 41m
用node1的ip:pod节点端口访问
192.168.85.133:30877
k8s中正确删除一个pod两个步骤
1、先删除pod
2、再删除对应的deployment
否则只是删除pod是不管用的,还会看到pod,因为deployment.yaml文件中定义了副本数量
①删除pod节点
kubectl delete pod -n <�名称空间>
kubectl delete pod nginx2-5648745967-787wg -n default
②删除deployment
kubectl delete deployment nginx2 -n default
后面加表示强制删除 –force –grace-period=0
清除污点
清除master节点
kubectl taint nodes –all node-role.kubernetes.io/master-
清除node节点
kubectl taint nodes k8s-node1 node.kubernetes.io/not-ready:NoSchedule-