-
修改docker mirror为阿里云:
vim /etc/docker/daemon.json
内容如下:
{ "registry-mirrors": ["https://xxx.mirror.aliyuncs.com"] }
-
运行rancher镜像:
docker run --name rancher -d --restart=unless-stopped \ -p 80:80 -p 443:443 \ rancher/rancher:stable
-
修改主机的hosts,方便访问:
vim /etc/hosts 127.0.0.1 rancher.site
-
添加节点:
sudo docker run -d --privileged --restart=unless-stopped --net=host -v /etc/kubernetes:/etc/kubernetes -v /var/run:/var/run rancher/rancher-agent:v2.0.8 --server https://rancher.site --token bnlvxdc8gqzc4sqvlrd6q2tbbk2f77lk4wsw66ns77rsdtx2kdsvzv --ca-checksum fae7cc19ed6a446b8429c42403c9e7a5fb957a26c7705343e61e6e104aa28497 --etcd --controlplane --worker
-
等待kubernetes安装完成:
https://rancher.site/c/c-9lc2x 此集群当前为Provisioning,在API准备就绪之前,直接与其交互的功能将不可用。
安装完毕之后,访问:https://rancher.site ,设置用户名密码。
-
为defalut service account授权(参考:https://jimmysong.io/kubernetes-handbook/concepts/rbac.html ),在主机上执行kubectl命令:
kubectl create clusterrolebinding serviceaccounts-cluster-admin \ --clusterrole=cluster-admin \ --group=system:serviceaccounts
-
修改主机的/etc/resolv.conf,添加自定义DNS,这样pod内部的container才能访问外部网络的DNS:
vim /etc/resolv.conf # Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN nameserver 114.114.114.114 nameserver 8.8.8.8
-
rancher运行jenkins镜像(带kubectl):
registry.cn-beijing.aliyuncs.com/im_wower/jenkins-in-kubernetes:lts-k8s
-
在jenkins的pod内部配置kubectl(参考:https://github.com/imwower/docker-kubectl ):
kubectl config set-cluster dev --certificate-authority=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt --embed-certs=true --server="https://kubernetes.default/" kubectl config set-credentials user --token="$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" kubectl config set-context default --cluster=dev --user=user kubectl config use-context default
-
测试kubectl是否正常:
kubectl get services
-
创建
setup_kubectl.sh
脚本,用于启动container时自动配置kubectl config:vim setup_kubectl.sh #!/bin/sh kubectl config set-cluster dev --certificate-authority=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt --embed-certs=true --server="https://kubernetes.default/" kubectl config set-credentials user --token="$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" kubectl config set-context default --cluster=dev --user=user kubectl config use-context default echo "finished." /usr/local/bin/jenkins.sh #用来启动jenkins
-
k8s部署jenkins的服务时,添加命令行(需要先将脚本以volume的形式挂载到pod上):
bash /var/jenkins_home/kube/setup_kubectl.sh
-
jenkins.yaml示例文件: https://gist.github.com/imwower/afdd8247179656b3f1cc3899740bb275
运行rancher 2.0
修改docker mirror为阿里云:vim /etc/docker/daemon.json内容如下:{"registry-mirrors": ["https://xxx.mirror.aliyuncs.com"]}运行rancher镜像:docker run ...
·
转载于:https://my.oschina.net/wower/blog/2050735
更多推荐
已为社区贡献2条内容
所有评论(0)