Kubernetes環境部署

簡介

Kubernetes 是一個開源系統,用於容器化應用的自動部署、擴縮和管理。它將構成應用的容器按邏輯單位進行分組以便於管理和發現。
 
配置鏡像源

Debian / Ubuntunode

apt-get update && apt-get install -y apt-transport-https
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF  
apt-get update

CentOS / RHEL / Fedoradocker

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

以centos爲例搭建環境

1.安裝:按照順序centos

yum install kubelet-1.13.12-0
yum install kubectl-1.13.12-0
yum install kubeadm-1.13.12-0


2.安裝後執行以下命令,先查看須要的鏡像文件:api

kubeadm config images list
-----------------------------
k8s.gcr.io/kube-apiserver:v1.13.12
k8s.gcr.io/kube-controller-manager:v1.13.12
k8s.gcr.io/kube-scheduler:v1.13.12
k8s.gcr.io/kube-proxy:v1.13.12
k8s.gcr.io/pause:3.1
k8s.gcr.io/etcd:3.2.24
k8s.gcr.io/coredns:1.2.6

3.導入並配置對應的鏡像文件app


docker load -i registry.aliyuncs.com.google_containers.kube-apiserver.tar
docker image ls
tag f07fae2c3e6a k8s.gcr.io/kube-apiserver:v1.13.12
docker load -i registry.aliyuncs.com.google_containers.kube-controller-manager.tar
docker image ls
docker tag 90fd4a237264 k8s.gcr.io/kube-controller-manager:v1.13.12
docker load -i registry.aliyuncs.com.google_containers.kube-scheduler.tar
docker image ls
docker tag 54f3185a42a5 k8s.gcr.io/kube-scheduler:v1.13.12
docker load -i registry.aliyuncs.com.google_containers.kube-proxy.tar
docker image ls
docker tag 4022daa30d3e k8s.gcr.io/kube-proxy:v1.13.12
docker load -i registry.aliyuncs.com.google_containers.pause.tar
docker image ls
docker tag da86e6ba6ca1 k8s.gcr.io/pause:3.1
docker load -i registry.aliyuncs.com.google_containers.etcd.tar
docker image ls
docker tag 3cab8e1b9802 k8s.gcr.io/etcd:3.2.24
docker load -i registry.aliyuncs.com.google_containers.coredns.tar
docker image ls
docker tag f59dcacceff4 k8s.gcr.io/coredns:1.2.6

4.導入並修改好鏡像名後執行curl

kubeadm init --pod-network-cidr=10.244.0.0/16

5.若出現報錯google

 

6.執行以下命令url

 kubeadm init --pod-network-cidr=10.244.0.0/16 --ignore-preflight-errors=swap

7.執行後若出現報錯:spa

 

 8.須要查看日誌:3d

journalctl --no-page -xeu kubelet
--或者 journalctl
--no-page -xeu kubelet|grep swap

 9.查看配置文件:

cd  /usr/lib/systemd/system/kubelet.service.d
[root@localhost kubelet.service.d]# ls
10-kubeadm.conf

10.找出配置文件中環境配置文件路徑

EnvironmentFile=-/etc/sysconfig/kubelet

 

 11.修改環境配置文件:

KUBELET_EXTRA_ARGS="--fail-swap-on=false"

 

 12.重啓kubeadm

kubeadm reset

 13.再次執行

kubeadm init --pod-network-cidr=10.244.0.0/16 --ignore-preflight-errors=swap

 

 14.環境搭建成功

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.4.131:6443 --token ft7m0e.i9z5x43zbaa1yk55 --discovery-token-ca-cert-hash sha256:4b3a2b2a4a164ca270d4173169eda4ec707ad16653387e6960185dcb76832837
相關文章
相關標籤/搜索