Kubernetes 搭建有四种方式,简单评价一下:
1.基于Docker 本地运行Kubernetes 先决条件: http://www.cnblogs.com/zhangeamon/p/5197655.html 参考资料: https://github.com/kubernetes/community/blob/master/contributors/devel/local-cluster/docker.md Install kubectl and shell auto complish: 评价: 这种方式我没有搭建成功,一直有can not connet 127.0.0.1:8080 的问题,后面感觉是没有创建./kube目录的原因。不过没有再试
2.用minikube minikube是一个适合于在单机环境下搭建,它是创建出一个虚拟机来,并且Kubernetes官方好像已经停止对基于Docker本地运行Kubernetes的支持,参考:https://github.com/kubernetes/minikube, 但是因为它最好要求是virtualbox作为底层虚拟化driver,而我的bare metal 已经安装kvm了,我试了下存在冲突,所以也就没有用这种方式进行安装。
3.用kubeadm 它是一个比较方便安装Kubernetes cluster的工具,我也是按照这种方式装成功的。后面会详细记录这种方式。
4.一步步安装 每一个组件每一个组件进行安装,我还没有试,可以根据:https://github.com/opsnull/follow-me-install-kubernetes-cluster, 比较麻烦。
5.在这里使用第三种kubeadm安装kunbernetes集群:1.Turn off SELinuxsudo setenforce 0sudo sed -i 's/enforcing/permissive/g' /etc/selinux/config2.Turn off firewalldsudo systemctl stop firewalldsudo systemctl disable firewalld3.Write the Kubernetes repository filecat
(这种方式主要是下载Kubernetes集群服务所需的微服务Docker镜像,同时由于FW的限制有的镜像不能下载,这时就需要通过某些方式从国内下载或者中转后重新tag镜像名称)
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
gpgcheck=0
EOF
docker pull registry.cn-hangzhou.aliyuncs.com/k8s16/kubernetes-dashboard-amd64
docker pull registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0
docker pull registry.cn-hangzhou.aliyuncs.com/kube_containers/kube-proxy-amd64:v1.6.4
docker pull registry.cn-hangzhou.aliyuncs.com/kube_containers/kube-scheduler-amd64:v1.6.4
docker pull registry.cn-hangzhou.aliyuncs.com/google-containers/dnsmasq-metrics-amd64
docker pull registry.cn-hangzhou.aliyuncs.com/kube_containers/k8s-dns-sidecar-amd64
vim /etc/sysctl.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-arptables = 1
images=(
pause-amd64:3.0
kube-proxy-amd64:v1.6.4
kube-scheduler-amd64:v1.6.4
kube-controller-manager-amd64:v1.6.4
kube-apiserver-amd64:v1.6.4
etcd-amd64:3.0.17
kube-discovery-amd64:1.0
kubedns-amd64:1.9
kube-dnsmasq-amd64:1.4
exechealthz-amd64:v1.2.0
dnsmasq-metrics-amd64:1.0
)
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 gcr.io/google_containers/$imageName
docker rmi registry.cn-hangzhou.aliyuncs.com/google-containers/$imageName
done
docker pull registry.cn-hangzhou.aliyuncs.com/kube_containers/k8s-dns-dnsmasq-nanny-amd64:1.14.1
images=(
pause-amd64:3.0
kube-proxy-amd64:v1.6.4
)
for imageName in ${images[@]} ; do
docker pull registry.cn-hangzhou.aliyuncs.com/kube_containers/$imageName
docker tag registry.cn-hangzhou.aliyuncs.com/kube_containers/$imageName gcr.io/google_containers/$imageName
docker rmi registry.cn-hangzhou.aliyuncs.com/kube_containers/$imageName
done
yum install -y docker kubelet kubeadm kubectl kubernetes-cni
[root@Master ~]# kubeadm init --pod-network-cidr=10.244.0.0/16
[kubeadm] WARNING: kubeadm is in beta, please do not use it for production clusters.
[init] Using Kubernetes version: v1.6.4
[init] Using Authorization mode: RBAC
[preflight] Running pre-flight checks
[preflight] Starting the kubelet service
[certificates] Generated CA certificate and key.
[certificates] Generated API server certificate and key.
[certificates] API Server serving cert is signed for DNS names [Master kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 10.10.10.21]
[certificates] Generated API server kubelet client certificate and key.
[certificates] Generated service account token signing key and public key.
[certificates] Generated front-proxy CA certificate and key.
[certificates] Generated front-proxy client certificate and key.
[certificates] Valid certificates and keys now exist in "/etc/kubernetes/pki"
[kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/admin.conf"
[kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/kubelet.conf"
[kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/controller-manager.conf"
[kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/scheduler.conf"
[apiclient] Created API client, waiting for the control plane to become ready
[apiclient] All control plane components are healthy after 14.788750 seconds
[apiclient] Waiting for at least one node to register
[apiclient] First node has registered after 5.003681 seconds
[token] Using token: e3d247.ab91b712406e2ecf
[apiconfig] Created RBAC rules
[addons] Created essential addon: kube-proxy
[addons] Created essential addon: kube-dns
Your Kubernetes master has initialized successfully!
To start using your cluster, you need to run (as a regular user):
sudo cp /etc/kubernetes/admin.conf $HOME/
sudo chown $(id -u):$(id -g) $HOME/admin.conf
export KUBECONFIG=$HOME/admin.conf
You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
http://kubernetes.io/docs/admin/addons/
You can now join any number of machines by running the following on each node
as root:
kubeadm join --token e3d247.ab91b712406e2ecf 10.10.10.21:6443
docker pull registry.cn-hangzhou.aliyuncs.com/google-containers/kubernetes-dashboard-amd64:v1.6.0
docker pull registry.cn-hangzhou.aliyuncs.com/google-containers/kubernetes-dashboard-amd64
images=(
kubernetes-dashboard-amd64:v1.6.0
)
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 gcr.io/google_containers/$imageName
docker rmi registry.cn-hangzhou.aliyuncs.com/google-containers/$imageName
done
网友评论