cat > /etc/yum.repos.d/kubernetes.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
yum install -y kubelet-1.17.3 kubeadm-1.17.3 kubectl-1.17.3
--设置kubelet开机启动:
systemctl enable kubelet
--开启kubelet默认是起不来的,后面会处理
systemctl start kubelet
执行权限chmod 700 master_images.sh
执行 ./master_images.sh
,文件如下:
#!/bin/bash
images=(
kube-apiserver:v1.17.3
kube-proxy:v1.17.3
kube-controller-manager:v1.17.3
kube-scheduler:v1.17.3
coredns:1.6.5
etcd:3.4.3-0
pause:3.1
)
for imageName in ${images[@]} ; do
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName
# docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName
k8s.gcr.io/$imageName
done
192.168.182.130这个是master节点地址
kubeadm init \
--apiserver-advertise-address=192.168.182.130 \
--image-repository registry.cn-hangzhou.aliyuncs.com/google_containers \
--kubernetes-version v1.17.3 \
--service-cidr=10.96.0.0/16 \
--pod-network-cidr=10.244.0.0/16
当步骤二kubeadm 初始化后,会在linux中生成以下的token令牌,复制这段代码到子节点中就可以配置成集群了
kubeadm join 192.168.182.130:6443 --token xiyzhk.o26530jlgl6ygxei \
--discovery-token-ca-cert-hash sha256:61c6e872765a61d530bdc368c5b174988ab77faef62a3caba54c5332a202496b
kubectl apply -f kube-flannel.yml
kubectl get nodes 查询当前主节点加入节点,必须所有节点状态都是Ready状态
watch kubectl get pod -n kube-system -o wide 查看Pod初始化进度
kubectl get pods -n kube-system 查看指定名称空间的pods
kubectl get pods --all-namespaces 查看所有名称空间的pods;一定得是running状态;
kubectl get all 获取K8s所有资源
kubectl get pods -o wide 获取各节点部署信息
kubectl get svc 查看服务
kubectl get svc -o wide
上一篇:2D和3D版本的重力游戏