How to configure kubernetes Version 1.28.1 lab using vagrant and ansible playbook
I am providing you here easy steps to create a lab for kubernetes, which will help in self learning
Pre-requiste:
- You need to download and install vagrant software from link: https://developer.hashicorp.com/vagrant/downloads
- Install oracle virutal machine from link: https://www.oracle.com/in/virtualization/technologies/vm/downloads/virtualbox-downloads.html
You can use below vagrant file to create centos8stream vagrant virtual machine.
Note:
Below configuration has 8GB RAM and 2 Core CPU, if needed you can still downgrade your configuration if required.
Your laptop should have atleast 16GB RAM and 4 Core CPU, if you are using below vagrant file without any changes.
Ensure to place below files same folder whether vagrant file is stored.
10-kubeadm.conf
bootstrap.sh
k8s-v1.28.playbook
k8s-v1.28-install.playbook
Finally your kubernetes Lab Setup is completed.
Now let’s deploy a sample deployment.
web-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: html-page-index
namespace: default
data:
index.html: |
<html>
<h1>Welcome to Kubernetes</h1>
</br>
<h1>This is kubernetes customized page loaded from html-page-index config map
</html>
custom-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
volumeMounts:
- name: nginx-index-file
mountPath: /usr/share/nginx/html/
volumes:
- name: nginx-index-file
configMap:
name: html-page-index
service.yaml
apiVersion: v1
kind: Service
metadata:
name: ngnix-service
spec:
selector:
app: nginx
type: NodePort
ports:
- protocol: TCP
port: 8080
targetPort: 80
Above are the sample files, and execute using below command
kubectl apply -f web-configmap.yaml
kubectl apply -f custom-deploy.yaml
kubectl apply -f service.yaml
Finally you have completed deployment using customized nginx, you can see the output here.
