k8s 部署jenkins篇之(helm3)
helm3 基础篇下载地址:https://github.com/helm/helm/releases如图:解压:tar -xfhelm-v3.0.0-linux-amd64.tar.gz安装:cp linux-amd64/helm/usr/bin/如图:5.helm基本语法:helm version #查看版本helm repo addmyhttps://kubernetes.oss-cn-ha
·
helm3 基础篇
- 下载地址:https://github.com/helm/helm/releases
- 如图:
- 解压:
tar -xf helm-v3.0.0-linux-amd64.tar.gz
- 安装:
cp linux-amd64/helm /usr/bin/
如图:
5.helm基本语法:
helm version #查看版本
helm repo add my https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts #添加阿里云源
helm repo list #产看源有哪些
helm repo remove my #删除源
helm search repo prometheus #搜索prometheus安装包
helm install myprometheus my/prometheus -n demon #安装prometheus,如果安装不上,可以pull下来,改改yaml,然后在部署,-n是名称空间。
helm fetch my/prometheus #下载
helm pull my/prometheus #下载,二选一。
helm install --dry-run myprometheus ./prometheus #提前浏览一下yaml文件。
helm install myprometheus ./prometheus #修改后的prometheus,安装部署。
helm upgrade myprometheus ./prometheus # 如果对yaml文件有所修改,就需要upgrade一下。
helm list #查看有哪些部署项目
helm history myprometheus #查看版本号信息
helm rollback myprometheus 1 #回退到1版本
helm delete myprometheus #删除项目
helm package myprometheus #打包项目
helm install jenkins -f my-jenkins-valuse.yaml . #指定valuse.yaml文件启动
helm template golang/ --output-dir ./golang-templates -f golang/values.yaml #生成模板文件
6.话不多说,上图:
7.我这儿自己定义个jenkins启动,来玩玩。有兴趣,可以一起。
7.1.pull
helm pull my/jenkins
7.2.解压:
tar -xf jenkins-0.13.5.tgz
7.3.修改文件信息:
cd jenkins
rm -rf templates/*.yaml #然后自己定义yaml,那就的说说helm的语法格式了,超级简单。
7.4.创建自己的yaml文件。我配上yaml文件。(所有的参数都可以用{{语法来定义}},我这儿只是简单演示。)
cat jenkins_deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: jenkins
namespace: {{ .Values.namespace }}
spec:
selector:
matchLabels:
app: jenkins
template:
metadata:
labels:
app: jenkins
spec:
terminationGracePeriodSeconds: 10
serviceAccount: jenkins
containers:
- name: jenkins
image: {{ .Values.images.name }}:{{ .Values.images.tag }}
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080 #外部访问端口
name: web
protocol: TCP
- containerPort: 50000 #jenkins save发现端口
name: agent
protocol: TCP
resources:
limits:
cpu: 1000m
memory: 1Gi
requests:
cpu: 500m
memory: 512Mi
livenessProbe:
httpGet:
path: /login
port: 8080
initialDelaySeconds: 60 #容器初始化完成后,等待60秒进行探针检查
timeoutSeconds: 5
failureThreshold: 12 #当Pod成功启动且检查失败时,Kubernetes将在放弃之前尝试failureThreshold次。放弃生存检查意味着重新启动Pod。而放弃就绪检查,Pod将被标记为未就绪。默认为3.最小值为1
readinessProbe:
httpGet:
path: /login
port: 8080
initialDelaySeconds: 60
timeoutSeconds: 5
failureThreshold: 12
volumeMounts: #需要将jenkins_home目录挂载出来
- name: jenkinshome
subPath: jenkins
mountPath: /var/jenkins_home
# env:
# - name: LIMITS_MEMORY
# valueFrom:
# resourceFieldRef:
# resource: limits.memory
# divisor: 1Mi
securityContext:
fsGroup: 1000
volumes:
- name: jenkinshome
persistentVolumeClaim:
claimName: opspvc
cat jenkins_rbac.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: jenkins
namespace: {{ .Values.namespace }}
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: jenkins
rules:
- apiGroups: ["extensions", "apps"]
resources: ["deployments"]
verbs: ["create", "delete", "get", "list", "watch", "patch", "update"]
- apiGroups: [""]
resources: ["services"]
verbs: ["create", "delete", "get", "list", "watch", "patch", "update"]
- apiGroups: [""]
resources: ["pods"]
verbs: ["create","delete","get","list","patch","update","watch"]
- apiGroups: [""]
resources: ["pods/exec"]
verbs: ["create","delete","get","list","patch","update","watch"]
- apiGroups: [""]
resources: ["pods/log"]
verbs: ["get","list","watch"]
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: jenkins
namespace: {{ .Values.namespace }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: jenkins
subjects:
- kind: ServiceAccount
name: jenkins
namespace: {{ .Values.namespace }}
cat jenkins_svc.yaml
apiVersion: v1
kind: Service
metadata:
name: jenkins
namespace: {{ .Values.namespace }}
labels:
app: jenkins
spec:
selector:
app: jenkins
type: NodePort
ports:
- name: web
port: 8080
targetPort: web
nodePort: 30002
- name: agent
port: 50000
targetPort: agent
7.5.nfs安装配置
yum -y install nfs-utils
mkdir -p /data/k8s
chown -R nfsnobody.nfsnobody /data
echo "/data/k8s 192.168.1.0/24(rw,no_root_squash,sync)" >/etc/exports
systemctl enable nfs
systemctl start nfs
showmount -e
#等下启动jenkins可能会报错,所以等jenkins目录出来之后授权一下,nfs下会出现jenkins目录。
useradd jenkins
chown -R jenkins.jenkins jenkins
chmod -R 777 jenkins
cat jenkins_pv.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: opspv
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Delete
nfs: #nfs配置
server: 192.168.1.4
path: /data/k8s
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: opspvc
namespace: {{ .Values.namespace }}
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Gi
7.6.终于可以来到values.yaml语法演讲了。
如图:
自己可以随便第一定义,yaml调用方式是{{ .Values.namespace }}。
cat my-jenkins-valuse.yaml
namespace: demon
images:
name: jenkins/jenkins
tag: lts
port: 8080
引用的 my-jenkins-valuse.yaml的变量
7.7.好了,开始启动了。
kubectl create ns demon
helm install jenkins -f my-jenkins-valuse.yaml .
helm list
7.8.查看pod,svc,deploy
kubectl get pod,svc,deploy -n demon
7.9.访问jenkins
浏览器打开:k8s-master的ip+30002端口。
8.0.jenkins密码
cat /data/k8s/jenkins/secrets/initialAdminPassword
。。。。。。溜溜球了,有啥问题评论区,讨论。。。。。。。
更多推荐
已为社区贡献14条内容
所有评论(0)