参考链接:
https://fabric8.io/
https://github.com/fabric8io
1. 下载gofabric8
地址:https://github.com/fabric8io/gofabric8/releases
通过测试的版本 version:0.4.157
2. fabric8安装需要使用pvc,所以配置StorageClass ,使用nfs
参考:http://blog.xianshiyue.com/216
3. 安装gofabric8
mkdir $HOME/.fabric8/bin
cp gofabric8-linux-amd64 gofabric8-linux-amd64
mv gofabric8-linux-amd64 gofabric8
export PATH=$PATH:$HOME/.fabric8/bin
4. 开始部署fabric8
gofabric8 deploy -y -d xianshiyue.com --namespace=fabric8
部署的过程中注意查看运行的pods,有些镜像下载很慢可以手动下载,可以去阿里云下载,然后 docker tag
https://dev.aliyun.com/list.html?namePrefix=kube
5. 给 fabric8
命令空间下的 serviceaccount
授权
检查pods 的运行状态都是running
,但是还是无法访问,检查pods 的日志,发现 exposecontroller
,configmapcontroller
无权访问kubernetes 的api, 我自己用了一个粗暴的方式,给命令空间下所有的 serviceaccount
授权,包括 default
eg:
kubectl create clusterrolebinding exposecontroller-cluster-admin-binding --clusterrole=cluster-admin --serviceaccount=fabric8:exposecontroller
kubectl create clusterrolebinding configmapcontroller-cluster-admin-binding --clusterrole=cluster-admin --serviceaccount=fabric8:configmapcontroller
kubectl create clusterrolebinding default-cluster-admin-binding --clusterrole=cluster-admin --serviceaccount=fabric8:default
kubectl create clusterrolebinding fabric8-cluster-admin-binding --clusterrole=cluster-admin --serviceaccount=fabric8:fabric8
6. 修改deployment ingress-nginx
的配置
6.1 导出yaml配置文件
kubectl get deployments ingress-nginx -nfabric8 -o yaml >> ingress-nginx.yaml
6.2 修改配置文件
把pods网络模式设置成 host,只需要添加 hostNetwork: true
eg:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
configmap.fabric8.io/update-on-change: nginx-config
deployment.kubernetes.io/revision: "3"
fabric8.io/git-branch: release-v2.2.311
fabric8.io/git-commit: 2b9f7ce19493fe6d18392ac4f4be16f5e1a76fa3
fabric8.io/iconUrl: https://cdn.rawgit.com/fabric8io/fabric8-devops/master/ingress-nginx/src/main/fabric8/icon.png
fabric8.io/metrics-path: dashboard/file/kubernetes-pods.json/?var-project=ingress-nginx&var-version=2.2.311
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"extensions/v1beta1","kind":"Deployment","metadata":{"annotations":{"configmap.fabric8.io/update-on-change":"nginx-config","deployment.kubernetes.io/revision":"2","fabric8.io/git-branch":"release-v2.2.311","fabric8.io/git-commit":"2b9f7ce19493fe6d18392ac4f4be16f5e1a76fa3","fabric8.io/iconUrl":"https://cdn.rawgit.com/fabric8io/fabric8-devops/master/ingress-nginx/src/main/fabric8/icon.png","fabric8.io/metrics-path":"dashboard/file/kubernetes-pods.json/?var-project=ingress-nginx\u0026var-version=2.2.311"},"creationTimestamp":"2017-10-23T14:45:38Z","generation":2,"labels":{"group":"io.fabric8.devops.apps","project":"ingress-nginx","provider":"fabric8","version":"2.2.311"},"name":"ingress-nginx","namespace":"fabric8","resourceVersion":"3294","selfLink":"/apis/extensions/v1beta1/namespaces/fabric8/deployments/ingress-nginx","uid":"d5bb1ec8-b800-11e7-a179-00163e0c10a2"},"spec":{"replicas":1,"selector":{"matchLabels":{"group":"io.fabric8.devops.apps","project":"ingress-nginx","provider":"fabric8"}},"strategy":{"rollingUpdate":{"maxSurge":1,"maxUnavailable":1},"type":"RollingUpdate"},"template":{"metadata":{"annotations":{"configmap.fabric8.io/update-on-change":"nginx-config","fabric8.io/git-branch":"release-v2.2.311","fabric8.io/git-commit":"2b9f7ce19493fe6d18392ac4f4be16f5e1a76fa3","fabric8.io/iconUrl":"https://cdn.rawgit.com/fabric8io/fabric8-devops/master/ingress-nginx/src/main/fabric8/icon.png","fabric8.io/metrics-path":"dashboard/file/kubernetes-pods.json/?var-project=ingress-nginx\u0026var-version=2.2.311"},"creationTimestamp":null,"labels":{"group":"io.fabric8.devops.apps","project":"ingress-nginx","provider":"fabric8","version":"2.2.311"}},"spec":{"containers":[{"args":["-v=3","-nginx-configmaps=fabric8-system/nginx-config"],"env":[{"name":"FABRIC8_NGINX_CONFIG_CONFIGMAP","value":"client-max-body-size=2000m;proxy-connect-timeout=500s;proxy-read-timeout=500s;server-names-hash-bucket-size=256;server-names-hash-max-size=1024"}],"image":"nginxdemos/nginx-ingress:0.3.1","imagePullPolicy":"IfNotPresent","name":"nginx-ingress","ports":[{"containerPort":80,"hostPort":80,"name":"http","protocol":"TCP"},{"containerPort":443,"hostPort":443,"name":"https","protocol":"TCP"}],"resources":{},"terminationMessagePath":"/dev/termination-log","terminationMessagePolicy":"File"}],"dnsPolicy":"ClusterFirst","hostNetwork":true,"nodeSelector":{"fabric8.io/externalIP":"true"},"restartPolicy":"Always","schedulerName":"default-scheduler","securityContext":{},"terminationGracePeriodSeconds":30}}},"status":{"availableReplicas":1,"conditions":[{"lastTransitionTime":"2017-10-23T14:45:38Z","lastUpdateTime":"2017-10-23T14:45:38Z","message":"Deployment has minimum availability.","reason":"MinimumReplicasAvailable","status":"True","type":"Available"}],"observedGeneration":2,"readyReplicas":1,"replicas":1,"updatedReplicas":1}}
creationTimestamp: 2017-10-23T14:45:38Z
generation: 3
labels:
group: io.fabric8.devops.apps
project: ingress-nginx
provider: fabric8
version: 2.2.311
name: ingress-nginx
namespace: fabric8
resourceVersion: "3872"
selfLink: /apis/extensions/v1beta1/namespaces/fabric8/deployments/ingress-nginx
uid: d5bb1ec8-b800-11e7-a179-00163e0c10a2
spec:
replicas: 1
selector:
matchLabels:
group: io.fabric8.devops.apps
project: ingress-nginx
provider: fabric8
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
annotations:
configmap.fabric8.io/update-on-change: nginx-config
fabric8.io/git-branch: release-v2.2.311
fabric8.io/git-commit: 2b9f7ce19493fe6d18392ac4f4be16f5e1a76fa3
fabric8.io/iconUrl: https://cdn.rawgit.com/fabric8io/fabric8-devops/master/ingress-nginx/src/main/fabric8/icon.png
fabric8.io/metrics-path: dashboard/file/kubernetes-pods.json/?var-project=ingress-nginx&var-version=2.2.311
creationTimestamp: null
labels:
group: io.fabric8.devops.apps
project: ingress-nginx
provider: fabric8
version: 2.2.311
spec:
containers:
- args:
- -v=3
- -nginx-configmaps=fabric8/nginx-config
image: nginxdemos/nginx-ingress:0.3.1
imagePullPolicy: IfNotPresent
name: nginx-ingress
ports:
- containerPort: 80
hostPort: 80
name: http
protocol: TCP
- containerPort: 443
hostPort: 443
name: https
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
hostNetwork: true ##=> 添加这一行
nodeSelector:
fabric8.io/externalIP: "true"
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
status:
availableReplicas: 1
conditions:
- lastTransitionTime: 2017-10-23T14:45:38Z
lastUpdateTime: 2017-10-23T14:45:38Z
message: Deployment has minimum availability.
reason: MinimumReplicasAvailable
status: "True"
type: Available
observedGeneration: 3
readyReplicas: 1
replicas: 1
updatedReplicas: 1
6.3 删除原来的deployment, 应用修改后的配置
kubectl delete -f ingress-nginx.yaml
kubectl create -f ingress-nginx.yaml
这个时候访问 配置的域名 http://xianshiyue.com 已经可以成功进入到控制台了
7. 最后修改 ingress-nginx
的configmap
如果域名配置太长的话,service
自动生成域名部署到nginx中将会报错,按照下图修改就OK