基础环境安装
主目录地址
初始化一个单机的集群
kubeadm init --pod-network-cidr="10.244.0.0/16" --image-repository=registry.aliyuncs.com/google_containers
执行结束,控制台会输出:
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
Alternatively, if you are the root user, you can run:
export KUBECONFIG=/etc/kubernetes/admin.conf
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 20.88.9.31:6443 --token 3e35of.fmihx78kxgbieizm \
--discovery-token-ca-cert-hash sha256:189db62b8e765e76c2b3dcb15e228cc4e6620994a2ae0e48504cd9e3cbe17e02
里面有两段需要关注的信息,一段是:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
这几条命令是吧kubernetes的配置文件复制到家目录下,当你执行kubectl命令时会默认使用家目录下的配置文件连接集群,当然也可以执行命令
export KUBECONFIG=/etc/kubernetes/admin.conf
指定配置文件的位置,不过执行后仅针对当前会话生效,需要添加到默认加载的文件中,如下
# 如果你执行了这一段,那么上面那段也就不起作用了,生效的配置是/etc/kubernetes/admin.conf文件.
echo 'export KUBECONFIG=/etc/kubernetes/admin.conf' >>/etc/profile;source /etc/profile
另一段是
kubeadm join 20.88.9.31:6443 --token 3e35of.fmihx78kxgbieizm \
--discovery-token-ca-cert-hash
执行kubeadm init
命令的节点为主节点,其他从节点想要加入集群,则执行此命令.