Helm部署和体验jenkins

2020-09-26  本文已影响0人  程序员欣宸

如何快速且简单的部署

通过helm可以快速且简单的部署多种应用,关于helm的安装和使用请参考

环境信息

本次实战的环境信息如下:

  1. kubernetes集群:三台CentOS7.7服务器
  2. kubernetes版本:1.15.3
  3. helm版本:2.16.1
  4. jenkins版本:

准备工作

除了提前准备好kubernetes环境,还需要做好以下准备工作:

本次实战的namespace

本次实战使用名为helm-jenkins的namespace,执行以下命令创建:

kubectl create namespace helm-jenkins

创建PV

为了后面的jenkins服务顺利启动,需要预先部署好pv:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: helm-jenkins
  namespace: helm-jenkins
spec:
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Recycle
  nfs:
    path: /usr/local/work/test/002
    server: 192.168.133.142
[root@node1 helm-jenkins]# kubectl get pv
NAME           CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM        STORAGECLASS   REASON   AGE
helm-jenkins   10Gi       RWO            Recycle          Available                                        5s
                         14h

helm安装jenkins

[root@node1 helm-jenkins]# helm version
Client: &version.Version{SemVer:"v2.16.1", GitCommit:"bbdfe5e7803a12bbdf97e94cd847859890cf4050", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.16.1", GitCommit:"bbdfe5e7803a12bbdf97e94cd847859890cf4050", GitTreeState:"clean"}
[root@node1 helm-jenkins]# helm repo list
NAME    URL                                                   
stable  https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
helm install --namespace helm-jenkins --name my-jenkins stable/jenkins
NOTES:
1. Get your 'admin' user password by running:
  printf $(kubectl get secret --namespace helm-jenkins my-jenkins -o jsonpath="{.data.jenkins-admin-password}" | base64 --decode);echo
2. Get the Jenkins URL to visit by running these commands in the same shell:
  NOTE: It may take a few minutes for the LoadBalancer IP to be available.
        You can watch the status of by running 'kubectl get svc --namespace helm-jenkins -w my-jenkins'
  export SERVICE_IP=$(kubectl get svc --namespace helm-jenkins my-jenkins --template "{{ range (index .status.loadBalancer.ingress 0) }}{{ . }}{{ end }}")
  echo http://$SERVICE_IP:8080/login

3. Login with the password from step 1 and the username: admin

上述内容的第一条给出了重要提示:获取admin账号密码的方法,执行命令即可:

printf $(kubectl get secret --namespace helm-jenkins my-jenkins -o jsonpath="{.data.jenkins-admin-password}" | base64 --decode);echo

如下图红框所示,我这里得到了admin密码为Eq6WxHvJ2V:

[root@node1 helm-jenkins]# kubectl get svc -n helm-jenkins
NAME               TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
my-jenkins         LoadBalancer   10.233.10.35   <pending>     8080:31763/TCP   31m
my-jenkins-agent   ClusterIP      10.233.35.20   <none>        50000/TCP        31m

设置kubernetes插件

为了让jenkins在以下模式工作,还需要设置kubernetes插件

[root@node1 helm-jenkins]# kubectl get serviceaccount -n helm-jenkins
NAME      SECRETS   AGE
default   1         3h55m

可见jenkins容器的serviceaccount是default

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: rbac-helm-jenkins-default
  namespace: helm-jenkins
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: default
  namespace: helm-jenkins

体验Freestyle project

[root@node1 helm-jenkins]# kubectl get pods -n helm-jenkins
NAME                          READY   STATUS              RESTARTS   AGE
default-66vcq                 0/1     ContainerCreating   0          1s
my-jenkins-74bcdfc566-jbw28   1/1     Running             0          5h5m

https://github.com/zq2599/blog_demos

上一篇 下一篇

猜你喜欢

热点阅读