K8s-jenkins-ci-cd project is just for learning CI/CD flow in local machine (ubuntu 18.04).
- Docker hub account
- GitHub account
- Install docker
https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-18-04 - Install kubectl
https://kubernetes.io/docs/tasks/tools/install-kubectl/ - Install minikube
https://github.com/kubernetes/minikube/releases - Install Jenkins
https://www.digitalocean.com/community/tutorials/how-to-install-jenkins-on-ubuntu-18-04
Minikube Setup
- Open minikube dashboard
After above, will show like following:
$ minikube start $ minikube dashboard
Open jenkins and Setup Plugins
-
Check Jenkins status
$ sudo systemctl status jenkins
-
Access jenkins
http://localhost:8080/ (default jenkins url) -
Install following plugins
- (Kubernetes) https://plugins.jenkins.io/kubernetes/
- (Blue Ocean) https://plugins.jenkins.io/blueocean/
-
Add k8s credentials
Jenkins
-->Manage Jenkins
-->Manage Credentials
-->Jenkins
-->Global credentials (unrestricted)
-->Add Credentials
- Fill
Secret text
inKind
- Fill token in
Secret
### will get secret name $ kubectl get secrets ### use above secret name (e.g. default-token-9f5cx) that will generate after above cmd $ kubectl describe secrets/<name of secrets> ### copy and paste token in Secret
- Fill
my_k8s
inID
- Click
OK
button
-
Add k8s cloud
Jenkins
-->Manage Jenkins
-->Configure system
- Scroll to bottom and in Add a new cloud, select
Kubernetes
- Fill
Kubenetes URL
with your minikube dashboard browser link (e.g. http://127.0.0.1:39659/) - Add credentials created in previous step in
Credentials
- Click
Test Connection
to check connect with local k8s - Click
Apply
andSave
button
-
Add docker hub credentials
Jenkins
-->Manage Jenkins
-->Manage Credentials
-->Jenkins
-->Global credentials (unrestricted)
-->Add Credentials
- Fill
Username with password
inKind
- Fill
<your_docker_hub_username>
inUsername
- Fill
<your_docker_hub_password>
inPassword
- Fill
docker_hub_login
inID
- Click
OK
button
Prepare GitHub Repository for sample kube Project
-
Fork
k8s-jenkins-ci-cd
Git repo.
https://github.com/aps1027/k8s-jenkins-ci-cd -
Change Docker hub repo name in code
- In
JenkinsFile
anddeployment.yaml
,
replace<docker_repo_name>
with your docker repo name. - Push Your Change to GitHub.
- In
-
Change kubernetes server url in code
- In
JenkinsFile
, replace<k8s_server_url>
with your kubernetes server url (e.g. http://127.0.0.1:39659/)
- In
Create New Jenkins Pipeline with Blue Ocean
- Click
Open Blue Ocean
in Jenkins Dashboard - Click
Create a new Pipeline
in Blue Ocean - Click
GitHub
inWhere do you store your codes?
- Click
<your_github_account_name>
and searchk8s-jenkins-ci-cd
inChoose a repository
- After All, You will see like the following:
Start Deployed App with minikube
-
Start Kubernetes Service
laravel-kubernetes-demo
$ minikube service laravel-kubernetes-demo
-
After All, your deployed App will appear in your browser like this:
https://learnk8s.io/blog/kubernetes-deploy-laravel-the-easy-way
https://www.linode.com/docs/development/ci/automate-builds-with-jenkins-on-ubuntu/
https://github.com/kenzanlabs/kubernetes-ci-cd
https://geekdudes.wordpress.com/2020/01/03/minikube-configure-jenkins-kubernetes-plugin/