<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://coolscript.net/index.php?action=history&amp;feed=atom&amp;title=Kubernetes_simple_deployment_with_service_and_configmap</id>
	<title>Kubernetes simple deployment with service and configmap - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://coolscript.net/index.php?action=history&amp;feed=atom&amp;title=Kubernetes_simple_deployment_with_service_and_configmap"/>
	<link rel="alternate" type="text/html" href="https://coolscript.net/index.php?title=Kubernetes_simple_deployment_with_service_and_configmap&amp;action=history"/>
	<updated>2026-06-02T18:20:41Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.40.1</generator>
	<entry>
		<id>https://coolscript.net/index.php?title=Kubernetes_simple_deployment_with_service_and_configmap&amp;diff=918&amp;oldid=prev</id>
		<title>Admin: Created page with &quot; =Intro= This article is based on the previois installation: Install Kubernetes 1.26 on Debian 11 with Flannel, the aim is to setup: *Simple cluster of two or more nginx p...&quot;</title>
		<link rel="alternate" type="text/html" href="https://coolscript.net/index.php?title=Kubernetes_simple_deployment_with_service_and_configmap&amp;diff=918&amp;oldid=prev"/>
		<updated>2023-03-14T16:18:15Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot; =Intro= This article is based on the previois installation: &lt;a href=&quot;/index.php/Install_Kubernetes_1.26_on_Debian_11_with_Flannel&quot; title=&quot;Install Kubernetes 1.26 on Debian 11 with Flannel&quot;&gt;Install Kubernetes 1.26 on Debian 11 with Flannel&lt;/a&gt;, the aim is to setup: *Simple cluster of two or more nginx p...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
=Intro=&lt;br /&gt;
This article is based on the previois installation: [[Install Kubernetes 1.26 on Debian 11 with Flannel]], the aim is to setup:&lt;br /&gt;
*Simple cluster of two or more nginx pods&lt;br /&gt;
*Create a service on top&lt;br /&gt;
*Use the Configmap to create content&lt;br /&gt;
*Apply the new content&lt;br /&gt;
&lt;br /&gt;
=Deployment=&lt;br /&gt;
deployment of 2 Nginx Pods (Replicas = 2)&lt;br /&gt;
*nginx-deployment.yaml&lt;br /&gt;
&lt;br /&gt;
 apiVersion: apps/v1&lt;br /&gt;
 kind: Deployment&lt;br /&gt;
 metadata:&lt;br /&gt;
   name: frontend-deployment&lt;br /&gt;
   labels:&lt;br /&gt;
     app: web&lt;br /&gt;
     tier: frontend&lt;br /&gt;
 spec:&lt;br /&gt;
   replicas: 2&lt;br /&gt;
   selector:&lt;br /&gt;
     matchLabels:&lt;br /&gt;
       tier: frontend&lt;br /&gt;
   template:&lt;br /&gt;
     metadata:&lt;br /&gt;
       labels:&lt;br /&gt;
         app: web&lt;br /&gt;
         tier: frontend&lt;br /&gt;
     spec:&lt;br /&gt;
       containers:&lt;br /&gt;
       - image: nginx:latest&lt;br /&gt;
         name: nginx&lt;br /&gt;
         ports:&lt;br /&gt;
         - containerPort: 30080&lt;br /&gt;
           name: nginx&lt;br /&gt;
&lt;br /&gt;
*Apply&lt;br /&gt;
 kubectl apply -f nginx-deplyoment.yaml&lt;br /&gt;
&lt;br /&gt;
*List&lt;br /&gt;
 kubectl get pods -o wide&lt;br /&gt;
 NAME                                   READY   STATUS    RESTARTS   AGE   IP            NODE             NOMINATED NODE   READINESS GATES&lt;br /&gt;
 frontend-deployment-6fb5bf7f54-4l2nv   1/1     Running   0          36s   10.244.2.12   vm-c1-worker-2   &amp;lt;none&amp;gt;           &amp;lt;none&amp;gt;&lt;br /&gt;
 frontend-deployment-6fb5bf7f54-mmfqb   1/1     Running   0          36s   10.244.1.10   vm-c1-worker-1   &amp;lt;none&amp;gt;           &amp;lt;none&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Service=&lt;br /&gt;
The service maps the label/app to &amp;#039;&amp;#039;&amp;#039;web&amp;#039;&amp;#039;&amp;#039; and associate the container port to port 80&lt;br /&gt;
* service.yaml&lt;br /&gt;
&lt;br /&gt;
 apiVersion: v1&lt;br /&gt;
 kind: Service&lt;br /&gt;
 metadata:&lt;br /&gt;
   name: example-service&lt;br /&gt;
   labels:&lt;br /&gt;
     app: web&lt;br /&gt;
 spec:&lt;br /&gt;
   type: NodePort&lt;br /&gt;
   selector:&lt;br /&gt;
     app: web&lt;br /&gt;
   ports:&lt;br /&gt;
     - protocol: TCP&lt;br /&gt;
       targetPort: 80&lt;br /&gt;
       port: 80&lt;br /&gt;
       nodePort: 30080&lt;br /&gt;
&lt;br /&gt;
*Apply&lt;br /&gt;
 kubectl apply -f service.yaml&lt;br /&gt;
&lt;br /&gt;
*List&lt;br /&gt;
&lt;br /&gt;
 kubectl get service -o wide&lt;br /&gt;
 NAME              TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE     SELECTOR&lt;br /&gt;
 example-service   NodePort    10.111.177.255   &amp;lt;none&amp;gt;        80:30080/TCP   8s      app=web&lt;br /&gt;
&lt;br /&gt;
=Testing=&lt;br /&gt;
&lt;br /&gt;
* Apply commands to the Pod, we want to add the hostname to the nginx welcome page&lt;br /&gt;
 &lt;br /&gt;
 kubectl get pods -o wide&lt;br /&gt;
 NAME                                   READY   STATUS    RESTARTS   AGE   IP            NODE             NOMINATED NODE   READINESS GATES&lt;br /&gt;
 &amp;#039;&amp;#039;&amp;#039;frontend-deployment-6fb5bf7f54-nq2bl&amp;#039;&amp;#039;&amp;#039;   1/1     Running   0          36s   10.244.2.12   vm-c1-worker-2   &amp;lt;none&amp;gt;           &amp;lt;none&amp;gt;&lt;br /&gt;
 &amp;#039;&amp;#039;&amp;#039;frontend-deployment-6fb5bf7f54-zj44m&amp;#039;&amp;#039;&amp;#039;   1/1     Running   0          36s   10.244.1.10   vm-c1-worker-1   &amp;lt;none&amp;gt;           &amp;lt;none&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Run commands inside of the pod==&lt;br /&gt;
&lt;br /&gt;
*Get the hostname&lt;br /&gt;
 kubectl exec frontend-deployment-6fb5bf7f54-nq2bl -- hostname&lt;br /&gt;
&lt;br /&gt;
*Replace the message on the first Pod:&lt;br /&gt;
 export khost=frontend-deployment-6fb5bf7f54-nq2bl&lt;br /&gt;
 kubectl exec &amp;#039;&amp;#039;&amp;#039;$khost&amp;#039;&amp;#039;&amp;#039; -- \&lt;br /&gt;
 sed -ir  &amp;quot;s/Welcome to nginx/Welcome to nginx on $HOSTNAME/gi&amp;quot; /usr/share/nginx/html/index.html&lt;br /&gt;
&lt;br /&gt;
*Replace the message on the second Pod:&lt;br /&gt;
 export khost=frontend-deployment-6fb5bf7f54-zj44m&lt;br /&gt;
 kubectl exec &amp;#039;&amp;#039;&amp;#039;$khost&amp;#039;&amp;#039;&amp;#039; -- \&lt;br /&gt;
 sed -ir  &amp;quot;s/Welcome to nginx/Welcome to nginx on $HOSTNAME/gi&amp;quot; /usr/share/nginx/html/index.html&lt;br /&gt;
&lt;br /&gt;
*Use curl to alternate between the pods&lt;br /&gt;
 curl -v --silent 10.111.177.255 2&amp;gt;&amp;amp;1 | grep &amp;#039;&amp;lt;title&amp;gt;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
=Get own content into the Nginx Pods=&lt;br /&gt;
==Configmap==&lt;br /&gt;
Get content to the cluster, create a simple index.html and add it to a configmap&lt;br /&gt;
 kubectl create configmap index.html --from-file index.html&lt;br /&gt;
 &lt;br /&gt;
 kubectl get configmaps&lt;br /&gt;
 NAME               DATA   AGE&lt;br /&gt;
 index.html         1      5m23s&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 kubectl describe configmap index.html&lt;br /&gt;
 Name:         index.html&lt;br /&gt;
 Namespace:    default&lt;br /&gt;
 Labels:       &amp;lt;none&amp;gt;&lt;br /&gt;
 Annotations:  &amp;lt;none&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 Data&lt;br /&gt;
 ====&lt;br /&gt;
 index.html:&lt;br /&gt;
 ...&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
=Rewrite the deployment=&lt;br /&gt;
&lt;br /&gt;
*Add the volumes to nginx-deployment.yaml&lt;br /&gt;
&lt;br /&gt;
 apiVersion: apps/v1&lt;br /&gt;
 kind: Deployment&lt;br /&gt;
 metadata:&lt;br /&gt;
   name: frontend-deployment&lt;br /&gt;
   labels:&lt;br /&gt;
     app: web&lt;br /&gt;
     tier: frontend&lt;br /&gt;
 spec:&lt;br /&gt;
   replicas: 2&lt;br /&gt;
   selector:&lt;br /&gt;
     matchLabels:&lt;br /&gt;
       tier: frontend&lt;br /&gt;
   template:&lt;br /&gt;
     metadata:&lt;br /&gt;
       labels:&lt;br /&gt;
         app: web&lt;br /&gt;
         tier: frontend&lt;br /&gt;
     spec:&lt;br /&gt;
       containers:&lt;br /&gt;
       - image: nginx:latest&lt;br /&gt;
         name: nginx&lt;br /&gt;
         ports:&lt;br /&gt;
         - containerPort: 30080&lt;br /&gt;
           name: nginx&lt;br /&gt;
         volumeMounts:&lt;br /&gt;
         - name: htmlcontent&lt;br /&gt;
           mountPath: &amp;quot;/usr/share/nginx/html/&amp;quot;&lt;br /&gt;
           readOnly: true&lt;br /&gt;
       volumes:&lt;br /&gt;
       - name: htmlcontent&lt;br /&gt;
         configMap:&lt;br /&gt;
           name: index.html&lt;br /&gt;
           items:&lt;br /&gt;
           - key: index.html&lt;br /&gt;
             path: index.html&lt;br /&gt;
&lt;br /&gt;
 kubectl apply -f nginx-deplyoment.yaml&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
</feed>