kubeadm部署kubernetes 1.13

环境信息

os:           Ubuntu 18.04.1 LTS
kernel:   4.15.0-42-generic
docker:   18.06.1-ce
ip:            10.10.5.226

准备工作

1.关闭防火墙

sudo ufw disable       

2.内核开启ipv4转发

$ sudo vim /etc/sysctl.conf
net.ipv4.ip_forward = 1             #开启ipv4转发,允许内置路由
$ sudo sysctl -p

3.防火墙修改FORWARD链默认策略

$vi /etc/docker/daemon.json
{
    "iptables": false
}

4.禁用swap

$ sudo swapoff -a

5.配置iptables参数

$ sudo tee /etc/sysctl.d/k8s.conf <<-'EOF'
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

$ sudo sysctl --system

6.安装docker 

安装kubeadm、kubelet、kubectl

创建kubernetes的repo

sudo apt-get update && sudo apt-get install -y apt-transport-https curl

sudo curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add -

sudo tee /etc/apt/sources.list.d/kubernetes.list <<-'EOF'
deb https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial main
EOF

sudo apt-get update

安装kubeadm、kubelet、kubectl

$ sudo apt-get install -y kubelet=1.13.0-00 kubeadm=1.13.0-00 kubectl=1.13.0-00
$ sudo apt-mark hold kubelet=1.13.0-00 kubeadm=1.13.0-00 kubectl=1.13.0-00#使这几个组件不更新
$ sudo systemctl enable kubelet && sudo systemctl start kubelet

Kubernetes集群安装

查看需要的镜像:

$ kubeadm config images list --kubernetes-version=v1.12.0

找个能过墙的机器。下载下来,然后导入到这个集群的所有机器。

查看默认的kubeadm配置:

 kubeadm config print init-defaults

修改networking.serviceSubnet和advertiseAddress,添加networking.podSubnet。如下:

apiVersion: kubeadm.k8s.io/v1beta1
bootstrapTokens:
- groups:
  - system:bootstrappers:kubeadm:default-node-token
  token: abcdef.0123456789abcdef
  ttl: 24h0m0s
  usages:
  - signing
  - authentication
kind: InitConfiguration
localAPIEndpoint:
  advertiseAddress: 10.10.5.226
  bindPort: 6443
nodeRegistration:
  criSocket: /var/run/dockershim.sock
  name: sjx
  taints:
  - effect: NoSchedule
    key: node-role.kubernetes.io/master
---
apiServer:
  timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta1
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controlPlaneEndpoint: ""
controllerManager: {}
dns:
  type: CoreDNS
etcd:
  local:
    dataDir: /var/lib/etcd
imageRepository: k8s.gcr.io
kind: ClusterConfiguration
kubernetesVersion: v1.13.0
networking:
  dnsDomain: cluster.local
  podSubnet: ""
  podSubnet: 192.168.0.0/16
  serviceSubnet: 10.96.0.0/12
scheduler: {}

集群初始化:

kubeadm init --config kubeadm-config.yaml

初始化完成之后就会告诉你后续步骤。包括加节点,配置kubelet。都是复制粘贴。

Your Kubernetes master 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/

You can now join any number of machines by running the following on each node
as root:

  kubeadm join 192.168.1.175:6443 --token v1nj22.l30dctzysf2jynly --discovery-token-ca-cert-hash sha256:0170607e7e069ffde2f2b6b440e7982f066887e59db49e9a62ac9518924af690

部署calico

 wget https://github.com/projectcalico/calico/releases/download/v3.4.0/release-v3.4.0.tgz

解压之后,把/release-v3.4.0/images导入集群:

docker load < release-v3.4.0/images/calico-cni.tar
docker load < release-v3.4.0/images/calico-kube-controllers.tar
docker load < release-v3.4.0/images/calico-node.tar
docker load < release-v3.4.0/images/calico-typha.tar

然后更改镜像名:

docker tag calico/node:v3.4.0 quay.io/calico/node:v3.4.0
docker tag calico/cni:v3.4.0 quay.io/calico/cni:v3.4.0
docker tag calico/kube-controllers:v3.4.0 quay.io/calico/kube-controllers:v3.4.0
docker tag calico/typha:v3.4.0 quay.io/calico/typha:v3.4.0

安装calico有两种方式。我这里用的第二种:https://docs.projectcalico.org/v3.4/getting-started/kubernetes/installation/calico

curl \
https://docs.projectcalico.org/v3.4/getting-started/kubernetes/installation/hosted/kubernetes-datastore/calico-networking/1.7/calico.yaml \
-O
POD_CIDR="192.168.0.0/16" \
sed -i -e "s?192.168.0.0/16?$POD_CIDR?g" calico.yaml#pod_cidr来自于kubeadm 配置文件添加的那个变量
kubectl apply -f calico.yaml

最后

kubectl get no
kubectl get po -n kube-system

查看集群节点和pod是否正常

Author: jxin

1 thought on “kubeadm部署kubernetes 1.13

发表评论

电子邮件地址不会被公开。 必填项已用*标注