安装docker
# 参考阿里云
# https://developer.aliyun.com/mirror/docker-ce?spm=a2c6h.13651102.0.0.3e221b11RIrnWN
# 编辑daemon
cat > /etc/docker/daemon.json <<EOF
{
"exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
安装kubernetes组件
# kubernetes镜像
# https://developer.aliyun.com/mirror/kubernetes?spm=a2c6h.13651102.0.0.3e221b11RIrnWN
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
# 安装 kubelet kubeadm kubectl
yum install -y --nogpgcheck kubelet kubeadm kubectl
# 配置kubelet的cgroup
cat <<EOF >/etc/sysconfig/kubelet
KUBELET_CGROUP_ARGS="--cgroup-driver=systemd"
KUBE_PROXY_MODE="ipvs"
EOF
# 启动
systemctl enable kubelet && systemctl start kubelet
准备集群镜像
// 查看需要镜像
[root@vigour ~]# kubeadm config images list
k8s.gcr.io/kube-apiserver:v1.22.2
k8s.gcr.io/kube-controller-manager:v1.22.2
k8s.gcr.io/kube-scheduler:v1.22.2
k8s.gcr.io/kube-proxy:v1.22.2
k8s.gcr.io/pause:3.5
k8s.gcr.io/etcd:3.5.0-0
k8s.gcr.io/coredns/coredns:v1.8.4
// 拉取镜像
kubeadm init \
--apiserver-advertise-address=192.168.43.128 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version=v1.22.2 \
--pod-network-cidr=10.244.0.0/16 \
--service-cidr=10.96.0.0/12
// 创建目录保存配置信息
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
// 加入集群
安装网络插件
wget https://github.com/caoran/kube-flannel.yml/blob/master/kube-flannel.yml
kubectl apply -f kube-flannel.yml
[root@master ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
master Ready control-plane,master 8m31s v1.22.2
node1 Ready <none> 84s v1.22.2
node2 Ready <none>
安装nginx
# 安装nginx
[root@master ~]# kubectl create deployment nginx --image=nginx:1.14-alpine
deployment.apps/nginx created
# 部署niginx
[root@master ~]# kubectl expose deployment nginx --port=80 --type=NodePort
service/nginx exposed
# 查看pod
[root@master ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
nginx-65c4bffcb6-g4ths 1/1 Running 0 44s
# 查看service
[root@master ~]# kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 48m
nginx NodePort 10.109.37.7 <none> 80:31182/TCP 20s
|