Deploy AtomicCD On Kubernetes Cluster
This tutorial shows how to deploy AtomicCD a Kubernetes Cluster with a Track Config file placed on a public Github repository.
Pre-requisites:
- A Kubernetes cluster with admin privileges.
- A Github public repository to place Target Config file.
- If repository is private: A Personal Access Token of the private repository (with read access for the repository contents). If using Github Fined-grained Tokens, the
Contentspermission withRead-onlyaccess can be used.
Below are the steps to setup AtomicCD to implement continuous delivery for a python application:
-
Create Cluster Role for AtomicCD:
- Make a file named
cluster-role.yamland copy the contents of the below cluster role file in it.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: sa-role
rules:
- apiGroups: ["apps"]
resources: ["deployments", "statefulsets"]
verbs: ["list", "patch"]
- apiGroups: [""]
resources: ["pods"]
verbs: ["list"]- Apply the file using
kubectl apply -f cluster-role.yamlcommand.
- Make a file named
-
Create a Service Account for AtomicCD
- Make a file named
sa.yamland copy the contents of the below service account file in it.
apiVersion: v1
kind: ServiceAccount
metadata:
name: sa
namespace: default- Apply the file using
kubectl apply -f sa.yamlcommand.
- Make a file named
-
Create a Cluster Role Binding to bind the above Service Account and Cluster Role with each other.
- Make a Cluster Role Binding file name
cluster-role-binding.yamland copy the contents of the below cluster role binding file in it.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: sa-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: sa-role
subjects:
- kind: ServiceAccount
name: sa
namespace: default- Apply the file using
kubectl apply -f cluster-role-binding.yamlcommand.
- Make a Cluster Role Binding file name
-
In your Github repository make a target config file named
targetConfig.yamlat root directory and copy the below target config files in it.
targetConfig:
- targetName: python-cd
containers:
- containerName: "python-container"
containerImage: "python"
containerTag: "3.9"
name: python-deployment
type: deployment
namespace: default
scope: nameScoped
-
Deploy a python deployment in your Kubernetes Cluster.
- Create a file named
python-deployment.yamland copy the python deployment manifest below in it.
apiVersion: apps/v1
kind: Deployment
metadata:
name: python-deployment
spec:
selector:
matchLabels:
app: python-deployment
template:
metadata:
labels:
app: python-deployment
spec:
containers:
- name: python-container
image: python:3.9
command: ["sh", "-c"]
args:
- |
bash -c "sleep 99999999"
resources:
limits:
memory: "128Mi"
cpu: "50m"
ports:
- containerPort: 80- Apply the file with
kubectl apply -f python-deployment.yamlcommand.
- Create a file named
-
Create a Configmap name with a Track Config file. Follow 6a if repository if public otherwise follow 6b
- (6a) Make a file named
configmap.yaml. Below in the track config configmap, replace "your github repository url" with your actual repository URL. Copy the final contents in yourconfigmap.yamlfile. Make sure the branch ismain.
apiVersion: v1
kind: ConfigMap
metadata:
name: atomic-cd-cm
data:
trackConfig.yaml: |
trackConfig:
repoURL: your github repository url
path: /targetConfig.yaml
token: your github personal access token- (6b) Make a file named
configmap.yaml. Below in the track config configmap, replace "your github repository url" with your actual repository URL. Change your github personal access token with the personal access token for your github private repository. Copy the final contents in yourconfigmap.yamlfile. Make sure the branch ismain.
apiVersion: v1
kind: ConfigMap
metadata:
name: atomic-cd-cm
data:
trackConfig.yaml: |
trackConfig:
repoURL: your github repository url
path: /targetConfig.yaml- Apply the file with
kubectl apply -f configmap.yamlcommand.
- (6a) Make a file named
-
Deploy AtomicCD
- Make a file named
deploy.yamland copy the contents of the below AtomicCD deployment manifest in it.
apiVersion: apps/v1
kind: Deployment
metadata:
name: atomic-cd
spec:
selector:
matchLabels:
app: atomic-cd
template:
metadata:
labels:
app: atomic-cd
spec:
serviceAccountName: sa
containers:
- name: atomic-cd
image: iamanshul14/atomiccd:v1
resources:
limits:
memory: "50Mi"
cpu: "30m"
volumeMounts:
- name: config-vol
mountPath: /AtomicCD/config
ports:
- containerPort: 8080
volumes:
- name: config-vol
configMap:
name: atomic-cd-cm- Apply the file using
kubectl apply -f deploy.yamlcommand.
- Make a file named
Trigger CD for the python application.
-
Get the name of AtomicCD pod by running the
kubectl get podscommand. Copy the pod name withatomic-cdprefix. -
In the command:
kubectl logs your-atomiccd-pod-name --follow, change "your-atomiccd-pod-name" with the AtomicCD pod name you copied above. Run the command. -
If everything goes fine you will see
runningoutput in the container log of AtomicCD. Do not close this terminal tab and keep tracking the logs. When you see therunninglog in AtomicCD pod it means that AtomicCD has scanned the Track Config in repository. -
Go to your Github repository and change the value of
containerTagfield to3.10and commit the change. -
AtomicCD scans for Track Config in github repo every 3 minutes, so wait for around 3 to 6 minutes and keep a track on AtomicCD container logs. The wait time can vary depending on the time you have commited changed container tag and last executed scan of AtomicCD so a little patience is required. Also Github caches the repository data so sometimes Github can provide AtomicCD outdated TrackConfig therefore for wait for around 2 to 3 scans of AtomicCD.
-
You will see the log
Out of sync Deployment: python-deployment with Container Name python-containerandSync Successfull!. This means AtomicCD have succefully executed CD for python app and change the python app version from3.9to3.10. -
You can confirm the changed python app version by first getting the pod name from the command:
kubectl get podsand copying the pod name with prefixpython-deploymentand then finally running the commandkubectl describe pod python-deployment-pod-name(change python-deployment-pod-name with the actual podname of python-deployment). -
In the result of above command you can check the container verson in
imagefield.