cd
cd manifests
mkdir ab
cd ab
# vi 01-cm-version1.yml
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-version-1
data:
index.html: |
<html>
<h1>Welcome to Version 1</h1>
</br>
<h1>Hi! This is a configmap Index file Version 1 </h1>
</html>
# vi 02-deployment-v1.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deploy-v1
spec:
selector:
matchLabels:
version: v1
replicas: 2
template:
metadata:
labels:
app: nginx
version: v1
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
volumeMounts:
- name: nginx-index-file
mountPath: /usr/share/nginx/html/
volumes:
- name: nginx-index-file
configMap:
name: nginx-version-1
# vi 03-cm-version2.yml
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-version-2
data:
index.html: |
<html>
<h1>Welcome to Version 2</h1>
</br>
<h1>Hi! This is a configmap Index file Version 2 </h1>
</html>
# vi 04-deployment-v2.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deploy-v2
spec:
selector:
matchLabels:
version: v2
replicas: 2
template:
metadata:
labels:
app: nginx
version: v2
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
volumeMounts:
- name: nginx-index-file
mountPath: /usr/share/nginx/html/
volumes:
- name: nginx-index-file
configMap:
name: nginx-version-2
# vi 05-svc.yml
apiVersion: v1
kind: Service
metadata:
name: my-nginx
labels:
svc: nginx
spec:
type: NodePort
ports:
- port: 80
protocol: TCP
selector:
app: nginx
kubectl apply -f .
# get external ip
kubectl get nodes -o wide
# get port
kubectl get svc my-nginx -o wide
# test it with curl apply it multiple time (at least ten times)
curl <external-ip>:<node-port>