#### 一、helm安装skywalking
##### 下载skywalking-kubernetes
```sh
$ git clone https://github.com/apache/skywalking-kubernetes.git
```
##### 配置skywalking
```bash
$ cd skywalking-kubernetes/chart
$ vim skywalking/values-my-es.yaml
```
```yaml
oap:
image:
tag: 8.7.0-es7 # Set the right tag according to the existing Elasticsearch version
storageType: elasticsearch7
ui:
image:
tag: 8.7.0
elasticsearch:
enabled: false
config: # For users of an existing elasticsearch cluster,takes effect when `elasticsearch.enabled` is false
host: es-cn-xxxxx.elasticsearch.aliyuncs.com
port:
http: 9200
user: "elastic" # [optional]
password: "xxxxxx" # [optional]
```
##### helm安装
```bash
$ export SKYWALKING_RELEASE_NAME=skywalking
$ export SKYWALKING_RELEASE_NAMESPACE=default
$ export REPO=skywalking
$ helm repo add ${REPO} https://apache.jfrog.io/artifactory/skywalking-helm
$ helm repo update
$ helm install "${SKYWALKING_RELEASE_NAME}" ${REPO}/skywalking -n "${SKYWALKING_RELEASE_NAMESPACE}" -f ./values-my-es.yaml
```
#### 二、微服务配置skywalking代理
制作skywalking-agent-sidecar镜像(`微服务的初始化容器`)
下载skywalking-agent
```bash
$ cd /opt/skywalking
$ wget https://dlcdn.apache.org/skywalking/8.7.0/apache-skywalking-apm-es7-8.7.0.tar.gz #es7表示elasticsearch 7
$ tar xvf apache-skywalking-apm-es7-8.7.0.tar.gz
$ cd apache-skywalking-apm-bin-es7/agent
$ /bin/cp -r optional-plugins/* plugins/ -f #注意:springboot gateway需要执行该操作,其他springboot微服务不需要
```
创建Dockerfile
```bash
$ cat Dockerfile
```
```bash
FROM busybox:latest
ENV LANG=C.UTF-8
RUN set -eux && mkdir -p /usr/skywalking/agent
add apache-skywalking-apm-bin-es7/agent /usr/skywalking/agent
WORKDIR /
```
生成镜像
```bash
$ docker build . -t skywalking-agent-sidecar:8.7.0-fixbug-1
```
修改deployment.yaml
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "springboot-demo.fullname" . }}
labels:
{{- include "springboot-demo.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "springboot-demo.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "springboot-demo.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "springboot-demo.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
initContainers: #增加初始化容器skywalking
- name: {{ .Values.image3.name }}
image: "{{ .Values.image3.repository }}:{{ .Values.image3.tag }}"
imagePullPolicy: IfNotPresent
command: ["sh"]
args:
[
"-c",
"mkdir -p /skywalking/agent && cp -r /usr/skywalking/agent/* /skywalking/agent",
]
volumeMounts:
- mountPath: /skywalking/agent
name: sw-agent
containers:
- name: {{ .Values.image2.name }}
image: "{{ .Values.image2.repository }}:{{ .Values.image2.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- "/bin/sh"
args:
- "-c"
- "filebeat -c /etc/filebeat/filebeat.yml"
volumeMounts:
- name: app-logs
mountPath: /log
- name: filebeat-{{.Release.Name}}-config
mountPath: /etc/filebeat/
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
- name: JAVA_TOOL_OPTIONS #微服务启动参数增加javaagent:skywalking-agent.jar
value: -javaagent:/usr/skywalking/agent/skywalking-agent.jar
- name: SW_AGENT_NAME #skywalking的名字
value: {{.Release.Name}}
- name: SW_AGENT_COLLECTOR_BACKEND_SERVICES #skywalking后端服务的地址:q!
value: skywalking-oap:11800
volumeMounts:
- name: app-logs
mountPath: /serverlog
- name: sw-agent #初始化容器挂载的skywalking文件
mountPath: /usr/skywalking/agent
ports:
- name: http
containerPort: {{ .Values.service.targetPort | default 80 }}
protocol: TCP
livenessProbe:
httpGet:
path: /actuator/health/liveness
port: {{ .Values.service.targetPort | default 80 }}
initialDelaySeconds: 20
failureThreshold: 15
timeoutSeconds: 10
periodSeconds: 5
readinessProbe:
httpGet:
path: /actuator/health/readiness
port: {{ .Values.service.targetPort | default 80 }}
initialDelaySeconds: 20
failureThreshold: 15
timeoutSeconds: 10
periodSeconds: 5
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumes:
- name: app-logs
emptyDir: {}
- name: sw-agent #skywalking目录
emptyDir: {}
- name: filebeat-{{.Release.Name}}-config
configMap:
name: filebeat-{{.Release.Name}}-config
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
```
value.yaml新增skywalking的配置
```yaml
...
image3:
name: skywalking-agent-sidecar
repository: xxxxx-k8s-registry-test-registry-vpc.cn-shenzhen.cr.aliyuncs.com/xxxxx/skywalking-agent-sidecar
pullPolicy: IfNotPresent
imagePullPolicy: Always
tag: "8.7.0-fixbug-1"
...
```