CI/CD Setup with CircleCI
Kubernetes Auto Deploy: CI/CD Setup with CircleCI
In this guide
oaicite:0
using
**
oaicite:1
**You will set up an automatic deployment process in the environment.
The goal is to automatically publish the application with every code update to GitHub.
What Will You Learn in This Guide?
- Creating a CI/CD pipeline with CircleCI
- Producing a Docker image and sending it to the registry
- Automatic deployment to Kubernetes
- Use commit-based versioning
Technical Summary
Topic: Automated CI/CD for Kubernetes
Problem: Manual deploy processes are error prone
Solution: CircleCI + Docker + Kubernetes automation
This structure:
- Triggered by GitHub push
- Works on container basis
- Provides scalable deployment
Prerequisites
Before continuing, you must have the following ready:
-
Kubernetes cluster (example:**
oaicite:2
Kubernetes**)
-
kubectlmust be installed -
Docker information
-
Docker Hub account
-
GitHub account
Access to Kubernetes Cluster
Once the cluster is created, test access to kubectl:
kubectl get nodes
- This command lists Kubernetes nodes.
If you see no resources found, access is successful.
Creating the Git Project
- Create a new folder for the sample application:
mkdir ~/k8s-sample-app && cd ~/k8s-sample-app
git init
- This repository will contain the CI/CD configuration.
Creating a Service Account for CI/CD
-
It is not recommended for CI systems to connect with the admin user.
-
Create Service Account definition:
apiVersion: v1
kind: ServiceAccount
metadata:
name: cicd
namespace: default
- This account is used only for CI/CD operations.
Apply:
kubectl apply -f cicd-service-account.yml
Role and RoleBinding Definition
- Define Service Account privileges:
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: cicd
namespace: default
rules:
- apiGroups: ["", "apps"]
resources: ["deployments", "services", "pods"]
verbs: ["*"]
- This role grants access to core Kubernetes resources.
Connect:
kubectl apply -f cicd-role.yml
kubectl apply -f cicd-role-binding.yml
Sample Application with Docker
- Create Dockerfile:
FROM nginx:1.21
COPY index.html /usr/share/nginx/html/index.html
- This image publishes static HTML.
Create the image:
docker build -t kullaniciadi/k8s-sample-app .
Test:
docker run -p 8080:80 kullaniciadi/k8s-sample-app
Kubernetes Deployment and Service
- Deployment description:
apiVersion: apps/v1
kind: Deployment
metadata:
name: k8s-sample-app
spec:
replicas: 1
selector:
matchLabels:
app: k8s-sample-app
template:
metadata:
labels:
app: k8s-sample-app
spec:
containers:
- name: app
image: kullaniciadi/k8s-sample-app:latest
ports:
- containerPort: 80
Service description:
apiVersion: v1
kind: Service
metadata:
name: k8s-sample-app
spec:
type: ClusterIP
selector:
app: k8s-sample-app
ports:
- port: 80
targetPort: 80
Apply:
kubectl apply -f kube/
CircleCI Configuration
- Create the .circleci/config.yml file:
version: 2.1
jobs:
build:
docker:
- image: circleci/buildpack-deps:bullseye
steps:
- checkout
- setup_remote_docker
- run: docker build -t app:latest .
- run: docker push app:latest
- This structure automatically generates the Docker image.
Commit Based Deploy
- Use commit hash instead of latest tag.
CircleCI variable:
$CIRCLE_SHA1
- In this way, each version is traceable.
- Deployment is done via script:
kubectl apply -f kube/
Frequently Asked Questions (FAQ)
-
Why do we use CircleCI? It's quick to install and integrated with GitHub.
-
Why is the latest tag not recommended? It makes version tracking difficult.
-
Is this structure suitable for prod? Yes, for small and medium-sized systems.
-
Can there be more than one environment? Yes, distinction can be made based on namespace.
Result
With this guide:
You have established a CI/CD pipeline with CircleCI
You generated Docker images automatically
You provided automatic deployment to Kubernetes
You can use this structure scalably and securely on the GenixNode Kubernetes infrastructure.

