Prerequisite:
K8s Cluster in GCP or AWS
Steps:
1) Create a yaml file for deployment, pod, replicaset, service in the format of .yml
2) Run the below command
kubectl create -f pod.yml
kubectl create -f replicaset.yml
kubectl create -f deployment.yml
kubectl create -f service.yml
pod.yml
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app: myapp
spec:
containers:
- name: nginx-image
image: nginx
replicaset.yml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: myapp-replicaset
labels:
app: myapp
type: front-end
spec:
template:
metadata:
name: myapp-pod
labels:
app: myapp
spec:
containers:
- name: nginx-image
image: nginx
replicas: 3
selector:
matchLabels:
app: myapp
Service.yml
apiVersion: v1
kind: Service
metadata:
name: myapp-service
spec:
type: NodePort
ports:
- targetPort: 80
port: 80
nodePort: 30008
selector:
app: myapp
output:
deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-replicaset
labels:
app: myapp
type: front-end
spec:
template:
metadata:
name: myapp-pod
labels:
app: myapp
spec:
containers:
- name: nginx-image
image: nginx
replicas: 3
selector:
matchLabels:
app: myapp
output:
3) Verify the pods and cluster, service
kubectl get all
kubectl get nodes -o wide
4) Install Helm
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
5) Create a Directory Helm and create a chart.
:>/ mkdir Helm
helm:>/helm create demochart
helm:>/ cd demochart
helm/demochart:>/ ls
6) remove the below files inside of templates
rm -rf _helpers hps, ingress.yaml, NOTES, serviceaccounts, tests
7) cd templates
create a deployment.yml and service.yml copy the above content and paste it.
8) Install the demochart
helm:>/ helm install myrelease demochart
output:
8) verify the cluster
helm:>/ kubectl get all
helm:>/ kubectl get nodes -o wide
localhost:>/helm template demochart
cd helm
helm:>/ ls
demochart
9) Convert helm file into ytt yml file
helm:>/ helm template demochart > ytt.yml
remove the commented # from the file
helm:/>kubectl get all
Now delete the deployment and service