# 1.初始化集群
kubeadm reset
kubeadm init --kubernetes-version=v1.10.1 --pod-network-cidr=10.244.0.0/16
# 可选
echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> /etc/profile
source /etc/profile
echo $KUBECONFIG #应该返回/etc/kubernetes/admin.conf
# 部署flannel网络
kubectl apply -f /opt/kubernetes-1.10/kube-flannel.yml
# 查看所有pod状态
kubectl get pod --all-namespaces
# 2.集群中增加节点
kubeadm reset
kubeadm join 192.168.30.11:6443 --token wtp7pf.rp8wb7p7iu15xsfk --discovery-token-ca-cert-hash sha256:7376232a605a09726675497ab969b3792028ce92fb528714f57b01543adedf46
# 3.部署k8s UI http://192.168.30.11:31000
kubectl apply -f kubernetes-dashboard-http.yaml
kubectl apply -f admin-role.yaml
kubectl apply -f kubernetes-dashboard-admin.rbac.yaml
# 4.部署微服务 http://192.168.30.11:30001
kubectl apply -f microarch-registry-dm.yaml
kubectl apply -f microarch-registry-svc.yaml
kubectl apply -f microarch-gateway-dm.yaml
kubectl apply -f microarch-gateway-svc.yaml
kubectl apply -f microarch-service-dm.yaml
kubectl apply -f webclient-dm.yaml
kubectl apply -f webclient-srv.yaml
# 5.安装weave监控
kubectl apply --namespace=weave -f "https://cloud.weave.works/k8s/scope.yaml?k8s-version=$(kubectl version | base64 | tr -d '
')"
# 6.helm安装
curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get | bash
如果安装失败,则单独下载helm-v2.12.3-linux-amd64.tar.gz 并执行安装:
tar -zxvf helm-v2.12.3-linux-amd64.tar.gzz
mv linux-amd64/helm /usr/local/bin/helm
# helm 的 bash 命令补全脚本,方法如下
helm completion bash > .helmrc
echo "source .helmrc" >> .bashrc
source .bashrc
# 7 安装Tiller服务器
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.12.3
helm init -i registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.10.0
# 初始化权限
· kubectl create serviceaccount --namespace kube-system tiller
kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'
# 8 将chart添加到仓库
# node节点上启动httpd容器
docker run -d -p 8080:80 -v /opt/helm_repo:/usr/local/apache2/htdocs/ httpd
# 打包mychart(/opt/helm/myrepo)
helm package mycharts
# 生成仓库的index文件
mkdir myrepo
mv mychart-0.1.0.tgz /myrepo/
helm repo index myrepo/ --url http://192.168.30.12:8080/charts
# 将mychart-0.1.0.tgz、index.yaml 上传到node节点的/opt/helm_repo/charts
scp *.* root@192.168.30.12:/opt/helm_repo/charts
# 通过helm repo add 将新仓库添加到Helm
helm repo add newrepo http://192.168.30.12:8080/charts
# 查询并安装
helm repo list
helm install newrepo/mychart
----------------------------------------------------------------------------------------
# 生成hash值,master上执行,参考 https://blog.csdn.net/mailjoin/article/details/79686934
openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'
kubectl get deployments
kubectl delete deployment registry-dm
kuebectl get pods
# 在线修改service端口
kubectl edit svc/weave-scope-app -n weave