1个版本 (0个不稳定版本)
1.0.0-alpha.1 | 2019年10月15日 |
---|
#37 in #health
1,536 个星标 & 81 个关注者
20KB
331 行
Health Scope控制器
HealthScope控制器用于定期检查所有组件的健康状况并更新健康范围自定义资源。
Health Scope控制器会做什么?
- 定期检查组件的健康状态并更新HealthScope资源状态。
- 作为http服务器,输出汇总的健康信息。
如何安装?
使用helm安装
helm install healthscope ./charts/healthscope
如何使用?
通过helm图表安装HealthScope控制器后,设置端点。默认情况下,图表将使用ClusterPort,我们可以使用port-forward来访问HealthScope控制器。
export POD_NAME=$(kubectl get pods -l "app.kubernetes.io/name=healthscope,app.kubernetes.io/instance=health" -o jsonpath="{.items[0].metadata.name}")
kubectl port-forward $POD_NAME 8080:80
然后我们就可以访问http://127.0.0.1:8080来查询HealthScope资源的状态。
使用应用程序配置创建Health Scope实例
如果您想使用Health Scope,您应该首先使用应用程序配置创建一个Health Scope实例。
一个Health Scope实例如下
apiVersion: core.oam.dev/v1alpha1
kind: ApplicationConfiguration
metadata:
name: my-health-scope
spec:
scopes:
- name: health
type: core.oam.dev/v1alpha1.HealthScope
properties:
- name: probe-method
value: "kube-get"
- name: probe-endpoint
value: ".status"
- name: probe-timeout
value: 30
- name: probe-interval
value: 60
- name: failure-rate-threshold
value: 0
- name: healthy-rate-threshold
value: 100.0
- name: healthThresholdPercentage
value: 100.0
您也可以在这里找到这个示例: examples/health-scope-config.yaml.
应用此yaml
$ kubectl apply -f examples/health-scope-config.yaml
applicationconfiguration.core.oam.dev/my-health-scope created
然后您将发现已创建了一个Health Scope实例
$ kubectl get health
NAME AGE
my-health-scope 31s
您可以从这里获取更多详细信息
$ kubectl get health my-health-scope -o yaml
apiVersion: core.oam.dev/v1alpha1
kind: HealthScope
metadata:
creationTimestamp: "2019-10-20T09:42:30Z"
generation: 3
name: my-health-scope
namespace: default
ownerReferences:
- apiVersion: core.oam.dev/v1alpha1
blockOwnerDeletion: true
controller: true
kind: ApplicationConfiguration
name: my-health-scope
uid: 1c113398-16f2-4aa1-9dc0-cd05a686d17d
resourceVersion: "2465881"
selfLink: /apis/core.oam.dev/v1alpha1/namespaces/default/healthscopes/my-health-scope
uid: ba3fd01c-9ba6-4e1a-93c0-b96d102700af
spec:
failureRateThreshold: 0
healthyRateThreshold: 100
probeEndpoint: .status
probeInterval: 60
probeMethod: kube-get
probeTimeout: 30
status:
lastAggregateTimestamp: "2019-10-20T09:43:31.541142387+00:00"
然后我们可以在其他应用程序配置中使用这个Health Scope。
将组件添加到Health Scope
我们将应用程序范围添加到我们的first-app-config.yaml
。
apiVersion: core.oam.dev/v1alpha1
kind: ApplicationConfiguration
metadata:
name: first-app
spec:
components:
- componentName: helloworld-python-v1
instanceName: first-app-helloworld-python-v1
parameterValues:
- name: target
value: Rudr
- name: port
value: "9999"
traits:
- name: ingress
properties:
hostname: example.com
path: /
servicePort: 9999
+ applicationScopes:
+ - my-health-scope
应用配置文件
$ kubectl apply -f examples/first-app-config.yaml
applicationconfiguration.core.oam.dev/first-app created
您可以像下面这样检查范围
$ kubectl get health -o yaml my-health-scope
apiVersion: core.oam.dev/v1alpha1
kind: HealthScope
metadata:
creationTimestamp: "2019-10-20T09:42:30Z"
generation: 10
name: my-health-scope
namespace: default
ownerReferences:
- apiVersion: core.oam.dev/v1alpha1
blockOwnerDeletion: true
controller: true
kind: ApplicationConfiguration
name: my-health-scope
uid: 1c113398-16f2-4aa1-9dc0-cd05a686d17d
resourceVersion: "2466413"
selfLink: /apis/core.oam.dev/v1alpha1/namespaces/default/healthscopes/my-health-scope
uid: ba3fd01c-9ba6-4e1a-93c0-b96d102700af
spec:
failureRateThreshold: 0
healthyRateThreshold: 100
probeEndpoint: .status
probeInterval: 60
probeMethod: kube-get
probeTimeout: 30
status:
components:
- instanceName: first-app-helloworld-python-v1
componentName: helloworld-python-v1
status: healthy
lastAggregateTimestamp: "2019-10-20T09:49:22.820141484+00:00"
状态表明我们已经成功将我们的组件添加到这个范围中。
访问Health Scope实例检查健康状态
您还记得我们第一步中的端口映射吗?使用我们的Health Scope实例访问该URL
$ curl 127.0.0.1:8080/my-health-scope
healthy
然后您会发现它现在健康了。
依赖关系
~76MB
~1.5M SLoC