Kubernetes入门实践
Kubernetes是一个基于容器技术的分布式架构,可以实现集群规模化部署,容器的部署以及对容器的操作(服务版本更新,迁移,调试)下面是通过kubeadm快速安装Kubernetes集群.配置Yum源:# cat magina-k8s.repo[magina-k8s]name=Magina K8s Repositorybaseurl=https://cdn.yinnote.co...
·
Kubernetes是一个基于容器技术的分布式架构,可以实现集群规模化部署,容器的部署以及对容器的操作(服务版本更新,迁移,调试)
下面是通过kubeadm快速安装Kubernetes集群.
配置Yum源:
# cat magina-k8s.repo [magina-k8s] name=Magina K8s Repository baseurl=https://cdn.yinnote.com/centos7/magina-k8s enabled=1 gpgcheck=0 gpgkey=https://cdn.yinnote.com/keys/rpm.public.key
安装rpm包:
yum makecache yum intall -y docker systemctl enable docker && systemctl start docker yum install -y kubelet-1.6.1 kubectl-1.6.1 kubeadm-1.6.1 systemctl enable kubelet && systemctl start kubelet
配置加速器:这个加速器是我自己的daocloud地址
# pwd /etc/docker # cat daemon.json {"registry-mirrors": ["http://62839702.m.daocloud.io"], "registry-mirror":[ "https://registry.docker-cn.com" ], "insecure-registries":[ "www.sholck.top:5000" ] } #systemctl daemon-reload && systemctl restart docker
编写脚本:(sholck是我的Docker Hub帐号 )
# cd /opt/ # cat k8s-docker-images.sh # 创建镜像下载脚本 ############################################# # 添加需要的镜像 images=( pause-amd64:3.0 kube-proxy-amd64:v1.6.1 kube-scheduler-amd64:v1.6.1 kube-controller-manager-amd64:v1.6.1 kube-apiserver-amd64:v1.6.1 etcd-amd64:3.0.17 k8s-dns-sidecar-amd64:1.14.1 k8s-dns-kube-dns-amd64:1.14.1 k8s-dns-dnsmasq-nanny-amd64:1.14.1 ) for imageName in ${images[@]} ; do docker pull sholck/$imageName docker tag sholck/$imageName gcr.io/google_containers/$imageName docker rmi sholck/$imageName done #############################################
执行脚本实现拉取镜像,清理
执行启动kubelet并安装集群
#kubeadm reset #systemctl start kubelet #kubeadm init --kubernetes-version=v1.6.1 --apiserver-advertise-address yourIP [kubeadm] WARNING: kubeadm is in beta, please do not use it for production clusters. [init] Using Kubernetes version: v1.6.1 [init] Using Authorization mode: RBAC [preflight] Running pre-flight checks [preflight] WARNING: docker version is greater than the most recently validated version. Docker version: 1.13.1. Max validated version: 1.12 [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 [jiche kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 47.94.201.186] [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 25.213093 seconds [apiclient] Waiting for at least one node to register [apiclient] First node has registered after 5.202103 seconds [token] Using token: e60caf.86ab3a734f1293ee [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 e60caf.86ab3a734f1293ee yourIP:6443
安装Node节点,加入集群.
# kubeadm join --token e60caf.86ab3a734f1293ee yourIP:6443 [kubeadm] WARNING: kubeadm is in beta, please do not use it for production clusters. [preflight] Running pre-flight checks [preflight] WARNING: docker version is greater than the most recently validated version. Docker version: 1.13.1. Max validated version: 1.12 [preflight] WARNING: hostname "chejian" could not be reached [preflight] WARNING: hostname "chejian" lookup chejian on 59.49.49.49:53: no such host [preflight] Starting the kubelet service [discovery] Trying to connect to API Server "yourIP:6443" [discovery] Created cluster-info discovery client, requesting info from "https://yourIP:6443" [discovery] Cluster info signature and contents are valid, will use API Server "https://yourIP:6443" [discovery] Successfully established connection with API Server "yourIP:6443" [bootstrap] Detected server version: v1.6.1 [bootstrap] The server supports the Certificates API (certificates.k8s.io/v1beta1) [csr] Created API client to obtain unique certificate for this node, generating keys and certificate signing request [csr] Received signed certificate from the API server, generating KubeConfig... [kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/kubelet.conf" Node join complete: * Certificate signing request sent to master and response received. * Kubelet informed of new secure connection details. Run 'kubectl get nodes' on the master to see this machine join.
master执行kubectl get nodes命令出现以下错误:
# kubectl get nodes The connection to the server localhost:8080 was refused - did you specify the right host or port?
问题来源:
查看 /etc/kubernetes/manifests/kube-apiserver.yaml中:–insecure-port=0
kube-apiserver的选项–insecure-port=0,也就是说kubeadm 1.6.0初始化的集群,kube-apiserver没有监听默认的http 8080端口。kube-apiserver只监听了https的6443端口。
解决方案:
在/etc/profile文件中追加:
export KUBECONFIG=/etc/kubernetes/admin.conf source /etc/profile
重行执行命令:
# kubectl get nodes NAME STATUS ROLES AGE VERSION chejian NotReady 13m v1.6.1 jiche NotReady master 14m v1.6.1
更多推荐
已为社区贡献1条内容
所有评论(0)