k8s单节点安装sitewhere 2.1

k8s配置部分参照
kubeadm安装Kubernetes 1.15(可单个节点k8s)

1、自己生成镜像或者从官方拉镜像

自己生成镜像的话参照, https://blog.csdn.net/tidehc/article/details/82881387
其中2、3、5步忽略就行。那些是Docker Compose安装用的
从官方拉最新镜像的话这一步忽略就行。

2、非安全模式安装Helm&Tiller:

需要安装Helm,Helm之于Kubernetes,好比yum于CentOS,便捷的包管理工具。
参考 https://docs.helm.sh/using_helm/#installing-helm
Helm使用指南参见https://docs.helm.sh/using_helm/#using_helm

(1)、安装Helm并创建ServiceAccount:

采用二进制包方式安装(snap方式据说大陆地区非常慢),参考https://github.com/helm/helm/releases

cd  /tmp

wget https://get.helm.sh/helm-v2.14.2-linux-amd64.tar.gz
tar -zxvf  helm-v2.14.2-linux-amd64.tar.gz 
mv linux-amd64/helm /usr/local/bin/helm
helm version

这里应该会提示一个Error: could not find tiller。
注意,默认情况下只需要执行 helm init 就可以完成tiller部署,而且看上去很正常,但是无法执行 helm install 。因为helm需要访问k8s的API,而我们的集群启用了RBAC,要让helm正常工作,我们需要为其配置好相关权限。

vim helm-rbac.yaml
---
apiVersion: v1
kind: ServiceAccount
metadata:
  labels:
    k8s-app: helm
  name: helm-admin
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: helm-admin
  labels:
    k8s-app: helm
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
  - kind: ServiceAccount
    name: helm-admin
    namespace: kube-system
-----------------------------------------------------------------------------
kubectl create -f helm-rbac.yaml
kubectl get sa --all-namespaces | grep helm

(2)安装Tiller

一般在镜像下载方面容易出问题:参考https://blog.csdn.net/weiguang1017/article/details/78045013
helm init在缺省配置下, Helm 会利用 “gcr.io/kubernetes-helm/tiller” 镜像在Kubernetes集群上安装配置 Tiller;并且利用 “https://kubernetes-charts.storage.googleapis.com” 作为缺省的 stable repository 的地址。由于在国内可能无法访问 “gcr.io”, “storage.googleapis.com” 等域名,阿里云容器服务为此提供了镜像站点。
使用下列命令安装:

helm init --upgrade --service-account helm-admin --upgrade  -i registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.14.2 --stable-repo-url https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
helm init --service-account helm-admin 

【默认的初始化执行方式】
然后helm version可以同时看到helm 和 tiller的版本号;
如果不是第一次则执行:

helm init --upgrade --service-account helm-admin  

上述执行时候的版本如果过旧,可以考虑执行更新;
首先查找新的镜像版本,放到私有仓库里去,

docker pull sapcc/tiller:v2.14.2
docker tag sapcc/tiller:v2.14.2 192.168.1.10:5000/sapcc/tiller:v2.14.2
docker push 192.168.1.10:5000/sapcc/tiller:v2.14.2

执行升级:

helm init --upgrade --service-account helm-admin  --tiller-image  192.168.1.10:5000/sapcc/tiller:v2.14.2 

(3)、安装后测试:

kubectl get svc --all-namespaces
helm version 应当能看见helm和tiller的版本号;
helm 
helm search 

如需清除Tiller等:
删除Tiller:
helm reset 或 $helm reset -f(强制删除k8s集群上的pod.)
当要移除helm init创建的目录等数据时,执行

helm reset --remove-helm-home

注:安全模式配置Helm【参考,并未做】:
https://docs.helm.sh/using_helm/#securing-your-helm-installation
https://docs.helm.sh/using_helm/#role-based-access-control

3、准备持久化存储rook

深入了解见:http://blog.51cto.com/bigboss/2320016?source=drha
Rook是一款运行在Kubernetes集群中的分布式存储服务编排工具,见官网:https://rook.io/
准备:创建路径:

mkdir -p /var/lib/rook
mkdir  -p  /etc/ceph 

{上述两个路径分别记录在cluster.yaml里,DirPath,和operator.yaml里}
以下操作在master节点进行:
sitewhere提供了rook安装文件

下载rook:git clone https://github.com/sitewhere/sitewhere-k8s.git
然后进入下载来的目录rook下,按顺序执行:

kubectl create -f rook/common.yaml
kubectl create -f rook/operator.yaml
kubectl create -f rook/cluster.yaml
kubectl create -f rook/storageclass.yaml
kubectl get pods --all-namespaces

查看应新增pods:mgr、mon、osd、osd-prepare
rook-ceph rook-ceph-mgr-a-5fd4fbc895-sh6lz 1/1 Running 0 4m
rook-ceph rook-ceph-mon-a-567cbf66c8-lcnh2 1/1 Running 0 4m
rook-ceph rook-ceph-osd-0-69778dd8f5-ld8tc 1/1 Running 0 3m
rook-ceph rook-ceph-osd-prepare-master-hkz9q 0/2 Completed 0 4m

kubectl get storageclass
NAME              PROVISIONER          AGE
rook-ceph-block   ceph.rook.io/block   7s

另外在各个node节点的/var/lib/rook下应可以看见rook-ceph文件夹、mon-a/b/c/…之类的文件和osd+数字的文件;
、将rook生成的存储设为默认storageclass【重要,后面的sitewhere里的consul使用默认存储,不设为默认的话consul-server无法运行】

kubectl patch storageclass rook-ceph-block -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'

再次查看:(应带有default)

kubectl get storageclass
NAME                        PROVISIONER          AGE
rook-ceph-block (default)   ceph.rook.io/block   1h

如需清除重新安装: 同样上述路径下
首先,您需要清理在Rook集群之上创建的资源

kubectl delete -f storageclass.yaml
kubectl delete -n rook-ceph cephblockpool replicapool
kubectl delete storageclass rook-ceph-block

删除CephCluster CRD

kubectl -n rook-ceph delete cephcluster rook-ceph
kubectl delete -f cluster.yaml

删除相关资源

kubectl delete -f operator.yaml
kubectl delete -f common.yaml

删除:

rm -rf /etc/ceph/*
rm -rf /var/lib/rook/*
rm -rf /dev/ceph-*

故障排除
如果清理说明没有按上述顺序执行,或者您在清理群集时遇到困难,可以尝试以下几种方法。

清理群集的最常见问题是rook-ceph命名空间或群集CRD在terminating状态中无限期保留。在删除所有资源之前,无法删除命名空间,因此请查看哪些资源正在等待终止。

看pods:

kubectl -n rook-ceph get pod

如果pod仍在终止,您将需要等待或尝试强制终止它(kubectl delete pod )。

现在看一下集群CRD:

kubectl -n rook-ceph get cephcluster

如果即使您之前已执行删除命令,群集CRD仍然存在,请参阅有关删除终结器的下一部分。

删除群集CRD终结器
创建群集CRD时,Rook运算符会自动添加终结器。终结器将允许操作员确保在删除集群CRD之前,将清除所有块和文件安装。如果没有适当的清理,消耗存储的pod将无限期挂起,直到系统重新启动。

在清洁底座后,操作员负责卸下终结器。如果由于某种原因操作员无法移除终结器(即操作员不再运行),您可以使用以下命令手动删除终结器:

kubectl -n rook-ceph patch crd cephclusters.ceph.rook.io --type merge -p '{"metadata":{"finalizers": [null]}}'

在几秒钟内,您应该看到群集CRD已被删除,并且将不再阻止其他清理,例如删除rook-ceph命名空间。

4、安装Istio

不知道什么是Istio的看这里 https://istio.io/zh/docs/concepts/what-is-istio/
说白了就是:Istio 是一个服务网格,其基本属性是监控和管理单个管理域下协作微服务网格的能力。服务网格本质上是将一组单独的微服务组合成单个可控的复合应用程序。

安装

下载设置并环境变量:

curl -L https://git.io/getLatestIstio | ISTIO_VERSION=1.2.2 sh -
cd istio-1.2.2
export PATH=$PWD/bin:$PATH

使用安装所有Istio 自定义资源定义 (CRD)kubectl apply,并等待几秒钟,以便在Kubernetes API服务器中提交CRD:

for i in install/kubernetes/helm/istio-init/files/crd*yaml; do kubectl apply -f $i; done

本地测试的话修改istio-demo.yaml中 LoadBalance为NodePort,否则一直pending

spec:
  type: NodePort
  selector:
    release: istio
    app: istio-ingressgateway
    istio: ingressgateway

运行以下命令以安装此变体:

kubectl apply -f install/kubernetes/istio-demo.yaml

确保部署了以下Kubernetes服务并验证它们是否具有适当CLUSTER-IP的jaeger-agent服务:
确保部署命名空间具有标签istio-injection=enabled,例如,对于default命名空间使用:

kubectl get svc -n istio-system
 
kubectl get namespace -L istio-injection
 
kubectl label namespace default istio-injection=enabled
 
NAME           STATUS    AGE       ISTIO-INJECTION
default        Active    1h        enabled
istio-system   Active    1h
kube-public    Active    1h
kube-system    Active    1h

如何卸载

如果有问题卸载,否则这一步忽略

kubectl delete -f install/kubernetes/istio-demo.yaml
for i in install/kubernetes/helm/istio-init/files/crd*yaml; do kubectl delete -f $i; done

5、安装sitewhere

从SiteWhere Helm Repository安装SiteWhere

如果你按照第一步自己生成了镜像,那就别在这折腾,直接跳过这一小步
要使用Helm安装SiteWhere,您需要将SiteWhere Helm存储库添加 到您的helm客户端。

helm repo add sitewhere https://sitewhere.io/helm-charts

然后,您需要更新本地helm存储库

helm repo update

提前拉一部分镜像及环境配置

提前获取镜像:【后期也会自动pull不过会比较慢】

docker pull ylonkar/pod-dependency-init-container:1.0
docker pull wurstmeister/kafka:1.0.0
docker pull wurstmeister/zookeeper:latest
docker pull elkozmon/zoonavigator-web:latest
docker pull docker.io/hashicorp/consul-k8s:0.1.0

创建路径:

mkdir -p /home/data/pv/
mkdir -p /consul/data
mkdir -p /consul/config
mkdir -p /consul/userconfig/
mkdir -p /data/db   
mkdir /kafka   
mkdir -p /opt/zookeeper-3.4.9/data

用Rook安装SiteWhere

**注意:**我这里假设你没有loadbalance,所以MQTT和web rest对外端口使用nodeport

否则去掉 --set infra.mosquitto.service.type=NodePort --set services.web_rest.service.http.type=NodePort

cd sitewhere-k8s/charts/sitewhere/
helm install --name sitewhere -f values-rook-ceph.yaml   --set infra.mosquitto.service.type=NodePort --set services.web_rest.service.http.type=NodePort sitewhere/sitewhere

如果没有自己生成而是去拉官方镜像会有点慢。最终完成后如下:

kubectl get pods
NAME                                             READY   STATUS    RESTARTS   AGE
sitewhere-asset-management-7b57665c5c-9zhns      2/2     Running   0          44h
sitewhere-batch-operations-69f78d7dfc-cnsgn      2/2     Running   0          44h
sitewhere-command-delivery-7465fc6bdb-2f962      2/2     Running   0          44h
sitewhere-cp-kafka-0                             1/1     Running   1          44h
sitewhere-cp-kafka-1                             1/1     Running   1          44h
sitewhere-cp-kafka-2                             1/1     Running   1          44h
sitewhere-cp-zookeeper-0                         1/1     Running   0          44h
sitewhere-cp-zookeeper-1                         1/1     Running   0          44h
sitewhere-cp-zookeeper-2                         1/1     Running   0          44h
sitewhere-device-management-566986c49f-qdsgf     2/2     Running   0          44h
sitewhere-device-registration-6fc7ddf75b-7j9sr   2/2     Running   0          44h
sitewhere-device-state-57fbbbd985-wtnqz          2/2     Running   0          44h
sitewhere-event-management-78dd56864f-f6p82      2/2     Running   0          44h
sitewhere-event-search-f78ddcdb5-wgh9k           2/2     Running   0          44h
sitewhere-event-sources-6d5bddcc88-c9dmw         2/2     Running   0          44h
sitewhere-inbound-processing-b848b8686-dzk4r     2/2     Running   0          44h
sitewhere-instance-management-5558f8ff66-gpxqw   2/2     Running   0          44h
sitewhere-label-generation-847d79cc7-w2cpm       2/2     Running   0          44h
sitewhere-mongodb-arbiter-0                      1/1     Running   0          44h
sitewhere-mongodb-primary-0                      1/1     Running   0          44h
sitewhere-mongodb-secondary-0                    1/1     Running   0          44h
sitewhere-mosquitto-59997444c4-rf8jr             1/1     Running   0          44h
sitewhere-outbound-connectors-55f945c6d4-n9xjj   2/2     Running   0          44h
sitewhere-postgresql-0                           1/1     Running   0          44h
sitewhere-rule-processing-7f5887786d-wkhtn       2/2     Running   0          44h
sitewhere-schedule-management-6747dfcd99-b48ts   2/2     Running   0          44h
sitewhere-streaming-media-79874d8647-2zfgz       2/2     Running   0          44h
sitewhere-syncope-6d48899c56-w4rdq               1/1     Running   0          44h
sitewhere-syncope-console-796dc94c54-q7zfl       1/1     Running   0          44h
sitewhere-syncope-enduser-64568b7f-l5dj8         1/1     Running   0          44h
sitewhere-web-rest-f5766bfb8-98lvw               2/2     Running   0          44h

端口你可以在k8s的Dashboard看,也可以kubectl get services 查看

 kubectl get services
NAME                                TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)                               AGE
kubernetes                          ClusterIP   10.1.0.1       <none>        443/TCP                               5d2h
sitewhere-asset-management-svc      ClusterIP   None           <none>        9000/TCP,9001/TCP,9090/TCP            47h
sitewhere-batch-operations-svc      ClusterIP   None           <none>        9000/TCP,9001/TCP,9090/TCP            47h
sitewhere-command-delivery-svc      ClusterIP   10.1.101.230   <none>        9001/TCP,9090/TCP                     47h
sitewhere-cp-kafka                  ClusterIP   10.1.34.151    <none>        9092/TCP                              47h
sitewhere-cp-kafka-headless         ClusterIP   None           <none>        9092/TCP                              47h
sitewhere-cp-zookeeper              ClusterIP   10.1.243.122   <none>        2181/TCP                              47h
sitewhere-cp-zookeeper-headless     ClusterIP   None           <none>        2888/TCP,3888/TCP                     47h
sitewhere-device-management-svc     ClusterIP   None           <none>        9000/TCP,9001/TCP,9090/TCP            47h
sitewhere-device-registration-svc   ClusterIP   10.1.201.48    <none>        9001/TCP,9090/TCP                     47h
sitewhere-device-state-svc          ClusterIP   10.1.176.201   <none>        9000/TCP,9001/TCP,9090/TCP            47h
sitewhere-event-management-svc      ClusterIP   None           <none>        9000/TCP,9001/TCP,9090/TCP            47h
sitewhere-event-search-svc          ClusterIP   10.1.10.19     <none>        9000/TCP,9001/TCP,9090/TCP            47h
sitewhere-event-sources-svc         ClusterIP   10.1.87.78     <none>        9001/TCP,9090/TCP                     47h
sitewhere-inbound-processing-svc    ClusterIP   10.1.221.40    <none>        9001/TCP,9090/TCP                     47h
sitewhere-instance-management-svc   ClusterIP   10.1.160.124   <none>        9001/TCP,9004/TCP,9005/TCP,9090/TCP   47h
sitewhere-label-generation-svc      ClusterIP   10.1.104.116   <none>        9000/TCP,9001/TCP,9090/TCP            47h
sitewhere-mongodb                   ClusterIP   10.1.163.143   <none>        27017/TCP                             47h
sitewhere-mongodb-headless          ClusterIP   None           <none>        27017/TCP                             47h
sitewhere-mosquitto-svc             NodePort    10.1.214.202   <none>        1883:31051/TCP                        47h
sitewhere-outbound-connectors-svc   ClusterIP   10.1.126.91    <none>        9001/TCP,9090/TCP                     47h
sitewhere-postgresql                ClusterIP   10.1.96.101    <none>        5432/TCP                              47h
sitewhere-postgresql-headless       ClusterIP   None           <none>        5432/TCP                              47h
sitewhere-rule-processing-svc       ClusterIP   10.1.45.19     <none>        9001/TCP,9090/TCP                     47h
sitewhere-schedule-management-svc   ClusterIP   None           <none>        9000/TCP,9001/TCP,9090/TCP            47h
sitewhere-streaming-media-svc       ClusterIP   10.1.25.170    <none>        9000/TCP,9001/TCP,9090/TCP            47h
sitewhere-syncope                   ClusterIP   10.1.42.196    <none>        8080/TCP                              47h
sitewhere-syncope-console           ClusterIP   10.1.90.226    <none>        8080/TCP                              47h
sitewhere-syncope-enduser           ClusterIP   10.1.58.20     <none>        8080/TCP                              47h
sitewhere-web-rest-grpc             ClusterIP   10.1.92.167    <none>        9001/TCP,9090/TCP                     47h
sitewhere-web-rest-http             NodePort    10.1.248.125   <none>        8080:30243/TCP                        47h

好了,根据上边的MQTT和web rest端口,下载一个sitewhere admin ui 2.1就可以玩了 默认用户名admin 密码password

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值