关于kubernetes:k8skubeadm

76次阅读

共计 3092 个字符,预计需要花费 8 分钟才能阅读完成。

参考文档:https://www.kubernetes.org.cn…



systemctl stop firewalld
systemctl disable firewalld

setenforce 0

swapoff -a

vi /etc/sysctl.d/k8s.conf
<code>
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
</code>

----modprobe br_netfilter
sysctl -p /etc/sysctl.d/k8s.conf



装置 Docker
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo


##yum makecache fast

yum install -y --setopt=obsoletes=0 docker-ce-18.06.1.ce-3.el7

systemctl start docker
systemctl enable docker

iptables -L


======api-server======
2. 应用 kubeadm 部署 Kubernetes

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
        https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF

yum install -y kubelet kubeadm kubectl

systemctl enable kubelet.service

kubeadm init \
  --kubernetes-version=v1.15.2 \
  --pod-network-cidr=10.244.0.0/16 \
  --apiserver-advertise-address=192.168.1.193


<output>
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

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 192.168.1.193:6443 --token bkghil.heogscphzlpgaq4d \
    --discovery-token-ca-cert-hash sha256:cad63137866251c1772c6c786fd1810998ed8b662179aca32bb04b4231003665 
</output>



mkdir /root/.kube
cp /etc/kubernetes/admin.conf /root/.kube/config
kubectl get cs


集群初始化如果遇到问题,能够应用上面的命令进行清理:<code>
kubeadm reset
ifconfig cni0 down
ip link delete cni0
ifconfig flannel.1 down
ip link delete flannel.1
rm -rf /var/lib/cni/
</code>


2.3 装置 Pod Network
mkdir -p ~/k8s/
cd ~/k8s
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl apply -f  kube-flannel.yml


kubectl get pod --all-namespaces -o wide 确保所有的 Pod 都处于 Running 状态。2.4 master 节点不参加调度,查看确认
[root@master ~]# kubectl describe node master | grep Taint
Taints:             node-role.kubernetes.io/master:NoSchedule

=======nodes========
2.5 向 Kubernetes 集群中增加 Node 节点
===node1=====
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
        https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF

yum install -y kubelet kubeadm



kubeadm join 192.168.1.193:6443 --token bkghil.heogscphzlpgaq4d --discovery-token-ca-cert-hash sha256:cad63137866251c1772c6c786fd1810998ed8b662179aca32bb04b4231003665

systemctl start kubelet.service
systemctl enable kubelet.service


2.6 测试 dns
kubectl run -i -t nameserver --image=tutum/dnsutils --restart=Never
root@nameserver:/# nslookup kubernetes.default
Server:        10.96.0.10
Address:    10.96.0.10#53

Name:    kubernetes.default.svc.cluster.local
Address: 10.96.0.1

正文完
 0