简体   繁体   English

在Kubernetes集群中部署Jenkins

[英]Deploy Jenkins in Kubernetes cluster

I'm begginer in Kubernetes and trying to deploy Jenkins in a cluster, but the pod is getting pending. 我在Kubernetes中是乞gg,试图在集群中部署Jenkins,但是pod即将挂起。

I need jenkins with access to kubernetes, including access to docker and kubectl commands, for continuos integration with my microservices. 我需要可以访问kubernetes的jenkins(包括访问docker和kubectl命令)来与我的微服务进行持续集成。

With this example yaml file, I can start a jenkins instance on a local machine (my notebook) through Minikube. 使用这个示例yaml文件,我可以通过Minikube在本地计算机(我的笔记本)上启动jenkins实例。

But now I'm trying to use a cloud cluster as part of my field of study. 但是现在,我正在尝试将云集群用作研究领域。

I accept suggestions for improvements. 我接受改进建议。

As I said: I just want to upload an instance of jenkins, with which I can continually integrate my micro services. 就像我说的那样:我只想上传jenkins的实例,通过它我可以不断集成我的微服务。

These are my configs and logs. 这些是我的配置和日志。

What is my mistake? 我怎么了

apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: jenkins-rbac
subjects:
  - kind: ServiceAccount
    name: default
    namespace: default
roleRef:
  kind: ClusterRole
  name: cluster-admin
  apiGroup: rbac.authorization.k8s.io
---
kind: PersistentVolume
apiVersion: v1
metadata:
  name: jenkins
  labels:
    type: local
spec:
  capacity:
    storage: 2Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/data/jenkins/"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: jenkins-claim
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 2Gi
---
apiVersion: v1
kind: Service
metadata:
  name: jenkins
  labels:
    app: jenkins
spec:
  ports:
    - port: 80
      targetPort: 8080
      nodePort: 32256
  selector:
    app: jenkins
    tier: jenkins
  type: NodePort
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: jenkins
  labels:
    app: jenkins
spec:
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: jenkins
        tier: jenkins
    spec:
      containers:
      - image: sammubr/jenkins
        name: jenkins
        securityContext:
          privileged: true
        ports:
        - containerPort: 8080
          name: jenkins
        volumeMounts:
        - name: jenkins-persistent-storage
          mountPath: /var/jenkins_home
        - name: docker
          mountPath: /var/run/docker.sock
      volumes:
      - name: docker
        hostPath:
          path: /var/run/docker.sock
      - name: jenkins-persistent-storage
        persistentVolumeClaim:
          claimName: jenkins-claim

Then kubectl --context do-sfo2-teste-cluster apply -f jenkins.yaml 然后kubectl --context do-sfo2-teste-cluster apply -f jenkins.yaml

But is allways pending: 但是一直待定:

samuel@samuel-Inspiron-5548:~/Documentos/teste/jenkins$ kubectl get all
NAME                           READY   STATUS    RESTARTS   AGE
pod/jenkins-5dc7fbd78d-9wxfl   0/1     Pending   0          8m34s

NAME                 TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
service/jenkins      NodePort    10.245.30.47   <none>        80:32256/TCP   8m34s
service/kubernetes   ClusterIP   10.245.0.1     <none>        443/TCP        79m

NAME                      READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/jenkins   0/1     1            0           8m35s

NAME                                 DESIRED   CURRENT   READY   AGE
replicaset.apps/jenkins-5dc7fbd78d   1         1         0       8m35s
samuel@samuel-Inspiron-5548:~/Documentos/teste/jenkins$ kubectl describe pod/jenkins-5dc7fbd78d-9wxfl
Name:               jenkins-5dc7fbd78d-9wxfl
Namespace:          default
Priority:           0
PriorityClassName:  <none>
Node:               <none>
Labels:             app=jenkins
                    pod-template-hash=5dc7fbd78d
                    tier=jenkins
Annotations:        <none>
Status:             Pending
IP:                 
Controlled By:      ReplicaSet/jenkins-5dc7fbd78d
Containers:
  jenkins:
    Image:        sammubr/jenkins
    Port:         8080/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:
      /var/jenkins_home from jenkins-persistent-storage (rw)
      /var/run/docker.sock from docker (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-5wdgs (ro)
Conditions:
  Type           Status
  PodScheduled   False 
Volumes:
  docker:
    Type:          HostPath (bare host directory volume)
    Path:          /var/run/docker.sock
    HostPathType:  
  jenkins-persistent-storage:
    Type:       PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
    ClaimName:  jenkins-claim
    ReadOnly:   false
  default-token-5wdgs:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-5wdgs
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason            Age               From               Message
  ----     ------            ----              ----               -------
  Warning  FailedScheduling  7s (x8 over 10m)  default-scheduler  pod has unbound immediate PersistentVolumeClaims (repeated 2 times)

As @ortomala-lokni mentioned earlier, you are having an issue with unbound PersistentVolumeClaims to the declared before PersitanceVolume, which causes eventually the Jenkins Pod unable to start up. 正如@ ortomala-lokni之前提到的,您遇到的问题是PersitentVolume之前声明的未绑定PersistentVolumeClaims,这最终导致Jenkins Pod无法启动。

In the shared link by @ortomala-lokni to the similar question on SO, one can read about various reasons of this error, and how to fix them. 在@ ortomala-lokni的共享链接上,也有关于SO的类似问题的信息,您可以了解到此错误的各种原因以及如何修复它们。

In your particular case the mismatch between what PVC's demands and PV provisioned actually on your cluster, is in accessModes (ReadWriteOnce vs. ReadWriteMany). 在您的特定情况下,PVC的需求与群集上实际配置的PV之间的不匹配是在accessModes中(ReadWriteOnce与ReadWriteMany)。

To fix your problem please update the 'PersistentVolumeClaim' definition accordingly, should look like this: 要解决您的问题,请相应地更新“ PersistentVolumeClaim”定义,如下所示:

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: jenkins-claim
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi

Note: 注意:
You don't need ' ReadWriteMany ' access mode with single replica of Jenkins Pod. 您不需要Jenkins Pod的单个副本的“ ReadWriteMany ”访问模式。 This is because with current definition of your 'jenkins' Deployment, under the hood the Deployment controller creates a ReplicaSet object, which by default ensures that only single instance of Jenkins Pod is running (= simplifying only single instance of Jenkins server will be writing to this volume at once). 这是因为在使用“ jenkins”部署的当前定义的情况下,Deployment控制器在后台创建了一个ReplicaSet对象,该对象默认情况下确保仅Jenkins Pod的单个实例正在运行(=简化为仅将Jenkins服务器的单个实例写入其中)一次)。

Please find here another tutorial on setting up Jenkins on Kubernetes from scratch, using helm (recommended way). 请在此处找到有关使用头盔从头开始在Kubernetes上设置Jenkins的另一教程(推荐方式)。

Remove quotation marks in PersistentVolume definition file in line: 在以下行中删除PersistentVolume定义文件中的引号:

 hostPath:
    path: "/data/jenkins/"

Correct file should look like: 正确的文件应如下所示:

apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: jenkins-rbac
subjects:
  - kind: ServiceAccount
    name: default
    namespace: default
roleRef:
  kind: ClusterRole
  name: cluster-admin
  apiGroup: rbac.authorization.k8s.io
---
kind: PersistentVolume
apiVersion: v1
metadata:
  name: jenkins
  labels:
    type: local
spec:
  capacity:
    storage: 2Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /data/jenkins/
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: jenkins-claim
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 2Gi
---
apiVersion: v1
kind: Service
metadata:
  name: jenkins
  labels:
    app: jenkins
spec:
  ports:
    - port: 80
      targetPort: 8080
      nodePort: 32256
  selector:
    app: jenkins
    tier: jenkins
  type: NodePort
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: jenkins
  labels:
    app: jenkins
spec:
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: jenkins
        tier: jenkins
    spec:
      containers:
      - image: sammubr/jenkins
        name: jenkins
        securityContext:
          privileged: true
        ports:
        - containerPort: 8080
          name: jenkins
        volumeMounts:
        - name: jenkins-persistent-storage
          mountPath: /var/jenkins_home
        - name: docker
          mountPath: /var/run/docker.sock
      volumes:
      - name: docker
        hostPath:
          path: /var/run/docker.sock
      - name: jenkins-persistent-storage
        persistentVolumeClaim:
          claimName: jenkins-claim

Apply changes; 应用更改;

 $ kubectl apply -f your-config-file.yaml

More information about PersistentVolumes and PersistentVolumeClaims you can find here: persistent-volume . 有关PersistentVolumesPersistentVolumeClaims的更多信息,您可以在这里找到: persistent-volume

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 github 工作流部署到 kubernetes 集群 - Deploy to kubernetes cluster with github workflow 在 Kubernetes 集群中部署内部 docker 镜像 - Deploy inhouse docker image in Kubernetes cluster 无法使用 Kompose 部署到 Kubernetes 集群 - Not able to deploy to Kubernetes cluster using Kompose Jenkins 构建 Docker 守护程序不在 kubernetes 集群上运行 - Jenkins build Docker daemon not running on kubernetes cluster Kube.netes 集群 pod 作为 Jenkins 构建代理 - Kubernetes cluster pods as Jenkins Build Agents 如何将一个简单的 Hello World 程序部署到本地 Kubernetes 集群 - How to deploy a simple Hello World program to local Kubernetes cluster 如何最好地在多台物理机上部署一个kubernetes集群? - How to deploy a kubernetes cluster on multiple physical machines in the best manner? 在 kubernetes 集群上使用 docker 命令运行 Jenkins 作业失败“docker:未找到” - Running Jenkins job with docker command on kubernetes cluster fails "docker: not found" 如何使用jenkins x在kubernetes上部署docker镜像 - How to deploy docker image on kubernetes using jenkins x Kubernetes 部署失败 jenkins 部署“无法创建容器任务” - Kubernetes deploy failed jenkins deployment "failed to create containerd task"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM