kubeadm简单安装k8s

  • One or more machines running a deb/rpm-compatible OS, for example Ubuntu or CentOS
  • 2 GB or more of RAM per machine. Any less leaves little room for your apps.
  • 2 CPUs or more on the master
  • Full network connectivity among all machines in the cluster. A public or private network is fine

一、.安装kubeadm

https://www.cnblogs.com/kevincaptain/p/10454817.html

 

二、安装k8s和设置网络的网段

  kubeadm init  --pod-network-cidr=192.168.0.0/16  #calico网络, 注意这个网段必须和物理主机的网络一样,不然会出现跨主机容器不能互访,或者容器不能访问外网

     

      如果是flannel ,需要设置为其他网段

    kubeadm init   --pod-network-cidr=10.244.0.0/16
    sysctl net.bridge.bridge-nf-call-iptables=1

 

三、配置文件

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

或者,如果您是root,则可以运行

export KUBECONFIG=/etc/kubernetes/admin.conf

 

四、安装网络 

这里可以选一些网络,https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/

#这里安装calico
kubectl apply -f https://docs.projectcalico.org/v3.3/getting-started/kubernetes/installation/hosted/rbac-kdd.yaml
kubectl apply -f https://docs.projectcalico.org/v3.3/getting-started/kubernetes/installation/hosted/kubernetes-datastore/calico-networking/1.7/calico.yaml

 

#如果按照flannel
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/a70459be0084506e4ec919aa1c114638878db11b/Documentation/kube-flannel.yml

 

想在master节点上部署pod的话,需要删除node的污点

kubectl taint nodes --all node-role.kubernetes.io/master-
#查看是否删除
kubectl  describe node 节点名字 |grep Taints

 查看服务是否启动成功

kubectl get pods --all-namespaces

 

五、加入节点

kubeadm join --token <token> <master-ip>:<master-port> --discovery-token-ca-cert-hash sha256:<hash>

查看有效时间24小时证书:

kubeadm token list

如果想得到永久证书,如下:

kubeadm token create

获取-证书ca-cert-hash:

openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | \
   openssl dgst -sha256 -hex | sed 's/^.* //'

最后执行加入:

kubeadm join --token 9x83na.7p03u114iod3nihx  192.168.33.3:6443 --discovery-token-ca-cert-hash sha256:2f255333c38981f544c3d333iiii531d9d7bead46004af2d83f4fc159751d70a8fa

 

 

参考:https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/

posted @ 2019-03-01 10:53  凯文队长  阅读(1036)  评论(0编辑  收藏  举报