Ubuntu 26.04

Kubernetes : Deploy Pods2026/05/12

 

This is the basic operation to create pods and others on Kubernetes Cluster.

In this example, a Kubernetes cluster is configured using four nodes as follows.

+----------------------+   +----------------------+
|  [ ctrl.srv.world ]  |   |   [ dlp.srv.world ]  |
|     Manager Node     |   |     Control Plane    |
+-----------+----------+   +-----------+----------+
        eth0|10.0.0.25             eth0|10.0.0.30
            |                          |
------------+--------------------------+-----------
            |                          |
        eth0|10.0.0.51             eth0|10.0.0.52
+-----------+----------+   +-----------+----------+
| [ node01.srv.world ] |   | [ node02.srv.world ] |
|     Worker Node#1    |   |     Worker Node#2    |
+----------------------+   +----------------------+

 

Work on Manager Node or Client Hosts you did setup cluster admin file.

[1] Create or Delete Pods.
# run [test-nginx] pods

ubuntu@ctrl:~$
kubectl create deployment test-nginx --image=nginx

deployment.apps/test-nginx created
ubuntu@ctrl:~$
kubectl get pods

NAME                          READY   STATUS    RESTARTS   AGE
test-nginx-5946d7969f-lmsxh   1/1     Running   0          7s

# show environment variable for [test-nginx] pod

ubuntu@ctrl:~$
kubectl exec test-nginx-5946d7969f-lmsxh -- env

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=test-nginx-5946d7969f-lmsxh
NGINX_VERSION=1.29.8
NJS_VERSION=0.9.6
NJS_RELEASE=1~trixie
ACME_VERSION=0.3.1
PKG_RELEASE=1~trixie
DYNPKG_RELEASE=1~trixie
KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443
KUBERNETES_PORT_443_TCP_PROTO=tcp
KUBERNETES_PORT_443_TCP_PORT=443
KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1
KUBERNETES_SERVICE_HOST=10.96.0.1
KUBERNETES_SERVICE_PORT=443
KUBERNETES_SERVICE_PORT_HTTPS=443
KUBERNETES_PORT=tcp://10.96.0.1:443
HOME=/root

# shell access to [test-nginx] pod

ubuntu@ctrl:~$
kubectl exec -it test-nginx-5946d7969f-lmsxh -- bash

root@test-nginx-5946d7969f-lmsxh:/#
exit

exit
# show logs of [test-nginx] pod

ubuntu@ctrl:~$
kubectl logs test-nginx-5946d7969f-lmsxh

/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2026/05/12 04:32:04 [notice] 1#1: using the "epoll" event method
2026/05/12 04:32:04 [notice] 1#1: nginx/1.29.8
2026/05/12 04:32:04 [notice] 1#1: built by gcc 14.2.0 (Debian 14.2.0-19)
2026/05/12 04:32:04 [notice] 1#1: OS: Linux 7.0.0-14-generic
2026/05/12 04:32:04 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1024:524288
.....
.....

# scale out pods

ubuntu@ctrl:~$
kubectl scale deployment test-nginx --replicas=3

deployment.extensions/test-nginx scaled
ubuntu@ctrl:~$
kubectl get pods -o wide

NAME                          READY   STATUS    RESTARTS   AGE     IP                NODE               NOMINATED NODE   READINESS GATES
test-nginx-5946d7969f-lmsxh   1/1     Running   0          2m26s   192.168.241.130   node02.srv.world   <none>           <none>
test-nginx-5946d7969f-q9xgg   1/1     Running   0          9s      192.168.40.194    node01.srv.world   <none>           <none>
test-nginx-5946d7969f-wh62b   1/1     Running   0          9s      192.168.241.131   node02.srv.world   <none>           <none>

# set service

ubuntu@ctrl:~$
kubectl expose deployment test-nginx --type="NodePort" --port 80

service "test-nginx" exposed
ubuntu@ctrl:~$
kubectl get services test-nginx

NAME         TYPE       CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
test-nginx   NodePort   10.100.101.233   <none>        80:30994/TCP   7s

# set port-forwarding and verify access

ubuntu@ctrl:~$
kubectl port-forward service/test-nginx --address 127.0.0.1 8082:80 &

[1] 4502
ubuntu@ctrl:~$
curl localhost:8082

<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
.....
.....
<p><em>Thank you for using nginx.</em></p>
</body>
</html>

# delete service

ubuntu@ctrl:~$
kubectl delete services test-nginx

service "test-nginx" deleted
# delete pods

ubuntu@ctrl:~$
kubectl delete deployment test-nginx

deployment.extensions "test-nginx" deleted
Matched Content