安装postgres
PVC,PV 使用NFS 存储(NFS 服务部署方式自行查询)
# [root@master sonarqube]# more pvc.yaml kind: PersistentVolumeClaim apiVersion: v1 metadata: name: postgres-pvc namespace: sonarqube-k8s spec: resources: requests: storage: 20Gi accessModes: - ReadWriteMany [root@master sonarqube]# more pv.yaml apiVersion: v1 kind: PersistentVolume metadata: name: sonarqube-k8s-pv spec: capacity: storage: 50Gi accessModes: - ReadWriteMany nfs: server: 10.0.8.16 # NFS 服务器 IP path: /data/postgres
Deployment
[root@master sonarqube]# cat postgres.yaml apiVersion: apps/v1 kind: Deployment metadata: name: postgres-sonar namespace: sonarqube-k8s labels: app: postgres-sonar k8s.eip.work/name: postgres-sonar k8s.eip.work/layer: db spec: replicas: 1 selector: matchLabels: app: postgres-sonar template: metadata: labels: app: postgres-sonar spec: containers: - name: postgres-sonar image: docker.io/library/postgres:latest #这里注意 imagePullPolicy: Always ports: - containerPort: 5432 env: - name: POSTGRES_DB value: sonar - name: POSTGRES_USER value: sonar - name: POSTGRES_PASSWORD value: sonar resources: limits: cpu: 1000m memory: 2048Mi requests: cpu: 500m memory: 1024Mi volumeMounts: - name: data mountPath: /var/lib/postgresql volumes: - name: data persistentVolumeClaim: claimName: postgres-pvc
Service
[root@master sonarqube]# cat postgres-service.yaml --- apiVersion: v1 kind: Service metadata: name: postgres-service namespace: sonarqube-k8s labels: app: postgres-sonar spec: type: NodePort ports: - port: 5432 targetPort: 5432 nodePort: 32333 selector: app: postgres-sonar
安装sonarqube
PVC
[root@master sonarqube]# cat sonarqube-pv.yaml # 创建 sonarqube—pv # sonarqube-pv.yaml 文件内容如下: --- apiVersion: v1 kind: PersistentVolume metadata: name: sonarqube2-k8s-pv spec: capacity: storage: 50Gi accessModes: - ReadWriteMany nfs: server: 10.0.8.16 path: /data/sonarqube --- [root@master sonarqube]# cat sonarqube-pvc.yaml # 创建 sonarqube—pvc # sonarqube-pvc.yaml 文件内容如下: --- kind: PersistentVolumeClaim apiVersion: v1 metadata: name: sonarqube2-pvc namespace: sonarqube-k8s spec: resources: requests: storage: 20Gi accessModes: - ReadWriteMany ---
Deployment
[root@master sonarqube]# cat sonarqube.yaml apiVersion: apps/v1 kind: Deployment metadata: name: sonarqube namespace: sonarqube-k8s labels: app: sonarqube spec: replicas: 1 selector: matchLabels: app: sonarqube template: metadata: labels: app: sonarqube spec: initContainers: - name: init-sysctl image: docker.io/library/busybox:latest imagePullPolicy: IfNotPresent command: ["sysctl", "-w", "vm.max_map_count=262144"] securityContext: privileged: true containers: - name: sonarqube #image: docker.io/library/sonarqube:latest image: docker.io/library/sonarqube:10.3-community ports: - containerPort: 9000 env: - name: SONARQUBE_JDBC_USERNAME value: "sonar" - name: SONARQUBE_JDBC_PASSWORD value: "sonar" - name: SONARQUBE_JDBC_URL #value: "jdbc:postgresql://postgres-sonar:5432/sonarDB" #value: "jdbc:postgresql://10.106.136.97:5432/sonarDB" #value: "jdbc:postgresql://10.99.101.19:5432/sonar" value: "jdbc:postgresql://postgres-service:5432/sonar" # 这里注意postgres-service的Name livenessProbe: httpGet: path: /sessions/new port: 9000 initialDelaySeconds: 60 periodSeconds: 30 readinessProbe: httpGet: path: /sessions/new port: 9000 initialDelaySeconds: 60 periodSeconds: 30 failureThreshold: 6 resources: limits: cpu: 2000m memory: 2048Mi requests: cpu: 1000m memory: 1024Mi volumeMounts: - mountPath: /opt/sonarqube/conf name: data subPath: conf - mountPath: /opt/sonarqube/data name: data subPath: data - mountPath: /opt/sonarqube/extensions name: data subPath: extensions volumes: - name: data persistentVolumeClaim: claimName: sonarqube2-pvc --- apiVersion: v1 kind: Service metadata: name: sonarqube namespace: sonarqube-k8s labels: app: sonarqube spec: type: NodePort ports: - name: sonarqube port: 9000 targetPort: 9000 nodePort: 30100 protocol: TCP selector: app: sonarqube
执行安装
[root@master sonarqube]# kubectl apply -f . service/postgres-service unchanged deployment.apps/postgres-sonar configured persistentvolume/sonarqube-k8s-pv unchanged persistentvolumeclaim/postgres-pvc unchanged persistentvolume/sonarqube2-k8s-pv unchanged persistentvolumeclaim/sonarqube2-pvc unchanged deployment.apps/sonarqube configured service/sonarqube unchanged
查看安装进度
[root@master sonarqube]# kubectl get po,svc -n sonarqube-k8s -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES pod/postgres-sonar-8648d79496-8d8d4 1/1 Running 0 17m 10.244.1.82 node1 <none> <none> pod/sonarqube-c76d5d478-4v9d9 1/1 Running 0 17m 10.244.1.81 node1 <none> <none> NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR service/postgres-service NodePort 10.109.121.244 <none> 5432:32333/TCP 17m app=postgres-sonar service/sonarqube NodePort 10.99.254.93 <none> 9000:30100/TCP 17m app=sonarqube
我这里使用的是NodePort 方式对外提供服务所以输入任何一Node节点IP+Port即 访问
默认用户名密码 admin
标签:postgres,部署,sonarqube,app,sonar,k8s,安装,name From: https://www.cnblogs.com/nb-blog/p/17988874