全程使用root用户运行,宿主机需要连接外网

浏览一下官方kubeadm【有些镜像用不了】

https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/

安装kubeadm[在对应目录下新建]

1. 添加kubernets repo

/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

2. dnf install kubeadm kubectl kubelet

3.安装docker-ce【按照docker推荐方式安装】

https://docs.docker.com/install/linux/docker-ce/centos/

4.安装指定版本docker-ce

dnf install docker-ce-18.06.2.ce

5. 配置docker的deamon.json【没有就新建】

/etc/docker/daemon.json

{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2",
"storage-opts": [
"overlay2.override_kernel_check=true"
],
"registry-mirror":"http://f1361db2.m.daocloud.io"
}

6. 重启docker

systemctl daemon-reload

systemctl restart docker

7.安装kubeadm基础环境依赖镜像

[root@apple ~]# kubeadm config images list --kubernetes-version v1.16.2

k8s.gcr.io/kube-controller-manager:v1.16.2
k8s.gcr.io/kube-scheduler:v1.16.2
k8s.gcr.io/kube-proxy:v1.16.2
k8s.gcr.io/pause:3.1
k8s.gcr.io/etcd:3.3.15-0
k8s.gcr.io/coredns:1.6.2

我们从aliyun下载镜像

新建 一个get_k8s_images.sh 脚本

chmod +x get_k8s_images.sh

./get_k8s_images.sh

#! /bin/bash

images=(
kube-apiserver:v1.16.2
kube-controller-manager:v1.16.2
kube-scheduler:v1.16.2
kube-proxy:v1.16.2
pause:3.1
etcd:3.3.15-0
coredns:1.6.2
)
for imageName in ${images[@]} ; do
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/${imageName}
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/${imageName} k8s.gcr.io/${imageName}
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/${imageName}
done

所有的依赖准备好了,我们启动一个单节点集群

[root@apple ~] kubeadm init --kubernetes-version v1.16.2 --apiserver-advertise-address 192.168.43.153 --pod-network-cidr 10.244.0.0/16

[init] Using Kubernetes version: v1.16.2

[preflight] Running pre-flight checks

[WARNING FileExisting-tc]: tc not found in system path

[preflight] Pulling images required for setting up a Kubernetes cluster

[preflight] This might take a minute or two, depending on the speed of your internet connection

[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'

[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"

[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"

[kubelet-start] Activating the kubelet service

[certs] Using certificateDir folder "/etc/kubernetes/pki"

[certs] Generating "ca" certificate and key

[certs] Generating "apiserver" certificate and key

[certs] apiserver serving cert is signed for DNS names [apple kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 192.168.43.153]

[certs] Generating "apiserver-kubelet-client" certificate and key

[certs] Generating "front-proxy-ca" certificate and key

[certs] Generating "front-proxy-client" certificate and key

[certs] Generating "etcd/ca" certificate and key

[certs] Generating "etcd/server" certificate and key

[certs] etcd/server serving cert is signed for DNS names [apple localhost] and IPs [192.168.43.153 127.0.0.1 ::1]

[certs] Generating "etcd/peer" certificate and key

[certs] etcd/peer serving cert is signed for DNS names [apple localhost] and IPs [192.168.43.153 127.0.0.1 ::1]

[certs] Generating "etcd/healthcheck-client" certificate and key

[certs] Generating "apiserver-etcd-client" certificate and key

[certs] Generating "sa" key and public key

[kubeconfig] Using kubeconfig folder "/etc/kubernetes"

[kubeconfig] Writing "admin.conf" kubeconfig file

[kubeconfig] Writing "kubelet.conf" kubeconfig file

[kubeconfig] Writing "controller-manager.conf" kubeconfig file

[kubeconfig] Writing "scheduler.conf" kubeconfig file

[control-plane] Using manifest folder "/etc/kubernetes/manifests"

[control-plane] Creating static Pod manifest for "kube-apiserver"

[control-plane] Creating static Pod manifest for "kube-controller-manager"

[control-plane] Creating static Pod manifest for "kube-scheduler"

[etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"

[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests". This can take up to 4m0s

[apiclient] All control plane components are healthy after 39.005910 seconds

[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace

[kubelet] Creating a ConfigMap "kubelet-config-1.16" in namespace kube-system with the configuration for the kubelets in the cluster

[upload-certs] Skipping phase. Please see --upload-certs

[mark-control-plane] Marking the node apple as control-plane by adding the label "node-role.kubernetes.io/master=''"

[mark-control-plane] Marking the node apple as control-plane by adding the taints [node-role.kubernetes.io/master:NoSchedule]

[kubelet-check] Initial timeout of 40s passed.

[bootstrap-token] Using token: utksay.ec8clj730but568m

[bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles

[bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials

[bootstrap-token] configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token

[bootstrap-token] configured RBAC rules to allow certificate rotation for all node client certificates in the cluster

[bootstrap-token] Creating the "cluster-info" ConfigMap in the "kube-public" namespace

[addons] Applied essential addon: CoreDNS

[addons] Applied essential addon: kube-proxy

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.43.153:6443 --token utksay.ec8clj730but568m

--discovery-token-ca-cert-hash sha256:5a26e6178ae4bd9d60ed19915540d633f216e6ea8f40ddd61013c1df68b3894e

9. 安装pod 网络

[root@apple ~]# wget https://raw.githubusercontent.com/coreos/flannel/2140ac876ef134e0ed5af15c65e414cf26827915/Documentation/kube-flannel.yml

[root@apple ~]# kubectl apply -f ./kube-flannel.yml

podsecuritypolicy.policy/psp.flannel.unprivileged created

clusterrole.rbac.authorization.k8s.io/flannel created

clusterrolebinding.rbac.authorization.k8s.io/flannel created

serviceaccount/flannel created

configmap/kube-flannel-cfg created

daemonset.apps/kube-flannel-ds-amd64 created

daemonset.apps/kube-flannel-ds-arm64 created

daemonset.apps/kube-flannel-ds-arm created

daemonset.apps/kube-flannel-ds-ppc64le created

daemonset.apps/kube-flannel-ds-s390x created

10. 查看cubectl api-versions

kubectl api-versions

admissionregistration.k8s.io/v1

admissionregistration.k8s.io/v1beta1

apiextensions.k8s.io/v1

apiextensions.k8s.io/v1beta1

apiregistration.k8s.io/v1

apiregistration.k8s.io/v1beta1

apps/v1

authentication.k8s.io/v1

authentication.k8s.io/v1beta1

authorization.k8s.io/v1

authorization.k8s.io/v1beta1

autoscaling/v1

autoscaling/v2beta1

autoscaling/v2beta2

batch/v1

batch/v1beta1

certificates.k8s.io/v1beta1

coordination.k8s.io/v1

coordination.k8s.io/v1beta1

events.k8s.io/v1beta1

extensions/v1beta1

networking.k8s.io/v1

networking.k8s.io/v1beta1

node.k8s.io/v1beta1

policy/v1beta1

rbac.authorization.k8s.io/v1

rbac.authorization.k8s.io/v1beta1

scheduling.k8s.io/v1

scheduling.k8s.io/v1beta1

storage.k8s.io/v1

storage.k8s.io/v1beta1

v1

11. ssh到节点的终端,输入下面命令加入集群

kubeadm join 192.168.43.153:6443 --token utksay.ec8clj730but568m

--discovery-token-ca-cert-hash sha256:5a26e6178ae4bd9d60ed19915540d633f216e6ea8f40ddd61013c1df68b3894e

tip: 关闭防火墙 关闭swap

最新文章

  1. Module Zero学习目录
  2. 如何通过cmd开一个本地服务器
  3. C++ TR1 Function Bind
  4. ArcGIS Engine中数据的加载 (转)
  5. Python学习笔记05
  6. [LintCode] Count and Say 计数和读法
  7. centos 用dvd创建yum 仓库
  8. 用腻了bootstrap的可以试试semantic-ui
  9. HTTP使用BASIC认证的原理及实现方法
  10. OC6_目录及文件的创建
  11. PHP 数组转字符串,与字符串转数组
  12. JBossESB教程(二)——将JBossESB部署到JBossAS中
  13. VS2013服务器资源管理器添加Mysql数据源
  14. Traveling
  15. Android设置Activity背景为透明style
  16. 将博客搬至CSDN https://blog.csdn.net/Fredric_2014
  17. servlet中 java.lang.ClassNotFoundException: com.mysql.jdbc.Driver异常
  18. 使用U盘为龙芯笔记本安装操作系统
  19. 【腾讯Bugly干货分享】经典随机Crash之二:Android消息机制
  20. JS知识整理之 Call&Apply方法

热门文章

  1. Ethical Hacking - GAINING ACCESS(2)
  2. Ethical Hacking - NETWORK PENETRATION TESTING(17)
  3. 享元模式(c++实现)
  4. p41_数据报与虚电路
  5. 题解 洛谷 P4177 【[CEOI2008]order】
  6. Python学习手册(第4版)PDF高清完整版免费下载|百度云盘
  7. Spring Cloud系列之使用Feign进行服务调用
  8. Python无限循环
  9. AJAX 是什么?
  10. PHP preg_match() 函数