In the previous article, we had k3S running successfully on MAC. So, today we take it one step further and deploy the Jenkins pipeline on top of it, just to see how k3S is in practice.


The steps are similar to yesterday, but the VM memory Settings are different:


1. Prepare Multipass VM and install K3S


Let’s create a VM with 2GB of memory and 50GB of disk


multipass launch --name k3s --mem 2G --disk 50GCopy the code


The same goes for installing K3S, but you need to always check the scripts that are running


multipass exec k3s -- sh -c "curl -sfL https://get.k3s.io | sh -"Copy the code


Copy kubeconfig file to host


multipass copy-files k3s:/etc/rancher/k3s/k3s.yaml .Copy the code


Use the following command: Multipass info k3s, list k3s information, in order to get the IP address, the address of the server from https://localhost:6443 with https://192.168.64.5:6443, export kubeconfig, confirm the node is working correctly.

export KUBECONFIG=k3s.yamlkubectl get nodesCopy the code

Now we are ready to develop the K3S environment. We don’t need to go into the VM because the host’s Kubectl command line is sufficient.




2. Dynamic storage classes


We need to provide dynamic storage in order to do some real work. We use the local volume provisioner (https://github.com/rancher/local-path-provisioner) to achieve this purpose. Download the YAML file and review it before using it.


curl -LO https://raw.githubusercontent.com/rancher/local-path-provisioner/master/deploy/local-path-storage.yamlCopy the code


Apply it and change this storage class to default storage.


kubectl apply -f local-path-storage.yaml
kubectl patch storageclass local-path -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'Copy the code


Now we are ready to store our classes dynamically.


3. Deploy Jenkins Helm Chart


K3s implements built-in support for HelmChart by providing CRD. We do not need to deploy the Tiller component or even the HELM command.


Let’s create a HelmChart CRD with the following code

apiVersion: k3s.cattle.io/v1kind: HelmChartmetadata:  name: jenkins  namespace: kube-systemspec:  chart: stable/jenkins  targetNamespace: jenkins  valuesContent: |-    Master:      AdminUser: {{ .adminUser }}      AdminPassword: {{ .adminPassword }}    rbac:      install: trueCopy the code

Note that the namespace in the metadata is used for the HelmChart object. K3s monitors CRD objects in kube-Sysytem, and if any new HelmChart object is created, the Helm installation job is started.


Chart defines which REPO and Helm Chart to deploy. Jenkins should be in the target namespace. Instead of using the “set” keyword in the Readme example, I use valuesContent so that I can apply the same format to it as Chart’s value.yaml file.


Save the file as jenkins.yaml without changing Jenkins. Create the target namespace and apply it as a Kubernetes object YAML file.

kubectl create ns jenkinskubectl apply -f jenkins.yamlCopy the code

The system starts to monitor the Helm installation job

kubectl -n kube-system get podsNAME                            READY   STATUS      RESTARTS   AGEcoredns-7748f7f6df-g6rgw        1/1     Running     0          138mhelm-install-jenkins-txxjn      0/1     Completed   0          111mhelm-install-traefik-bnc5x      0/1     Completed   0          138msvclb-traefik-b65f58f65-rxllp   2/2     Running     0          138mtraefik-5cc8776646-nfclx        1/1     Running     0          138mCopy the code


Verify that the PVC is bound


kubectl -n jenkins get pvcNAME      STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGEjenkins   Bound    pvc-18988281-4d45-11e9-b75c-5ef9efd9374c   8Gi        RWO            local-path     113mCopy the code


Also verify that the POD is running.


kubectl -n jenkins get podsNAME                             READY   STATUS    RESTARTS   AGEjenkins-6b6f58bc8d-hbf4r         1/1     Running   0          113msvclb-jenkins-74fdf6b9f4-zxnwz   1/1     Running   0          113mCopy the code


4. Interview Jenkins


Finding a service port


Kubectl -n Jenkins get svcNAME TYPE cluster-ip external-ip PORT(S) AGEjenkins LoadBalancer 10.43.75.62 192.168.64.5 8080:30254/TCP 115mJenkins - Agent ClusterIP 10.43.239.13 < None > 50000/TCP 115MCopy the code


Now, we can through http://192.168.64.5:8080. Visit Jenkins as follows:




If you want to know more about the skills of using K3S, welcome to attend the K3S offline Workshop held in Shenzhen on October 26. Senior architects from Rancher Labs will introduce the functions, features and application scenarios of K3S for you in detail and conduct a live demo. It will also take you to build a K3S cluster with your own laptop. Click here to sign up!