Configure a Jenkins pipeline on Kubernetes with Github and Slack


  • 这里使用的是 a free IBM Cloud account.

    Install the IBM Cloud command-line interface (CLI) to your work station.

  • 本机 Mac 使用 Docker Desktop.

    同时 Create a Docker Hub account.

  • Install a Kubernetes CLI (kubectl) on Mac
  • Install a Git Client.

    Sign up for a GitHub account.

  • Create a Slack account.

Key Procedure

  • 设置 KUBECONFIG 环境变量, 指向 cloud。

  • 验证是否可以连接到集群。
    kubectl version --short

    Client Version: v1.16.1
    Server Version: v1.14.9+IKS

  • 持久化 jenkins_home。因为这里使用的是单节点集群,所以 pv 类型选用的是 hostPath。

    kubectl apply -f jenkins-pv.yaml
    kubectl apply -f jenkins-pvc.yaml
    kubectl apply -f jenkins-deployment.yaml
    kubectl apply -f jenkins-service.yaml

  • 获取 Jenkins dashboard 服务地址
    export EXTERNAL_IP=$(kubectl get nodes -o jsonpath='{.items[0].status.addresses[?(@.type=="ExternalIP")].address }')

    export NODE_PORT=30100


  • 获取 Jenkins admin 默认密码

    kubectl logs $(kubectl get pods --selector=app=jenkins -o=jsonpath='{.items[0]}') jenkins

  • 配置凭据 github、dockerhub、kubeconfig、slack-notification

  • 安装插件:Slack-notification 和Kubernetes Cli Plugin

  • 配置 Jenkins Slack Notification 主要填写 Workspace, Credential。Default channel / member id 可不填,具体可在 Jenkinsfile 配置里指定,比如

    success { slackSend(channel: "#ok", message: "pluckhuang/podinfo:${env.BUILD_NUMBER} Pipeline is successfully completed.")}

Reference and resource

k8s in action summary ~3


  • Give replicated pods individual storage
  • Provide a stable identity to a pod
  • Create a StatefulSet and a corresponding headless governing Service
  • Scale and update a StatefulSet
Discover other members of the StatefulSet through DNS
  • Connect to other members through their host names
  • Forcibly delete stateful pods


  • 何谓有状态?就是说具有 stable identity,比如name,ip,storage。
  • dns srv 记录,类似负载均,只不过是 service -> map pod with ip

Qos class:

  • besteffort
  • burstable
  • guaranteed

Qos class 是 Quality of Service (QoS) classes 的简写,是当no CPU time at all and will be the first ones killed when memory needs to be freed for other pods. 时的依据处理方式。

resource requests limit and qos classes

which pods get killed first


主要是介绍了 helm 的使用方法。helm 类似于 yum、apt,只不过是作为构建在 k8s 之上的包管理工具。

  • 期间了解 helm 遇到个小问题:

    helm install happy-panda stable/mariadb
    helm uninstall stable/mariadb
    helm install happy-panda stable/mariadb 会失败,原因是 uninstall stable/mariadb 并不会删除相关的 pvc。