{"id":16403,"date":"2023-05-21T14:44:59","date_gmt":"2023-05-21T11:44:59","guid":{"rendered":"https:\/\/kifarunix.com\/?p=16403"},"modified":"2024-03-10T09:13:03","modified_gmt":"2024-03-10T06:13:03","slug":"step-by-step-guide-on-deploying-an-application-on-kubernetes-cluster","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/step-by-step-guide-on-deploying-an-application-on-kubernetes-cluster\/","title":{"rendered":"Step-by-Step Guide on Deploying an Application on Kubernetes Cluster"},"content":{"rendered":"\n<p>In this tutorial, we will provide you with a step-by-step guide on deploying an application on Kubernetes cluster. Kubernetes is the de facto container orchestration tool that helps to deploy and manage applications in an efficient and scalable way. In this tutorial, we&#8217;ll walk you through the steps of deploying an application on Kubernetes cluster from beginning to end including creating a container image to configuring a Kubernetes service. Let&#8217;s get started!<\/p>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#deploying-an-application-on-kubernetes-cluster\">Deploying an Application on Kubernetes Cluster<\/a><ul><li><a href=\"#getting-started-with-kubernetes\">Getting Started with Kubernetes<\/a><\/li><li><a href=\"#setup-kubernetes-cluster\">Setup Kubernetes Cluster<\/a><\/li><li><a href=\"#create-a-docker-container-image\">Create a Docker Container Image<\/a><\/li><li><a href=\"#create-kubernetes-deployment-and-service-manifests\">Create Kubernetes Deployment and Service Manifests<\/a><ul><li><a href=\"#configure-kubernetes-cluster-to-trust-local-docker-registry-with-self-signed-ssl-certs\">Configure Kubernetes Cluster to Trust Local Docker Registry with Self Signed SSL Certs<\/a><\/li><li><a href=\"#create-kubernetes-application-deployment-manifest-on-master-node\">Create Kubernetes Application Deployment Manifest on Master Node<\/a><\/li><li><a href=\"#create-kubernetes-application-service-manifest-on-master-node\">Create Kubernetes Application Service Manifest on Master Node<\/a><\/li><li><a href=\"#checking-kubernetes-pods-containers-logs\">Checking Kubernetes Pods\/Containers Logs<\/a><\/li><li><a href=\"#login-to-specific-kubernetes-pod-or-container-in-a-pod\">Login to Specific Kubernetes Pod or Container in a Pod<\/a><\/li><\/ul><\/li><li><a href=\"#accessing-kubernetes-application\">Accessing Kubernetes Application<\/a><\/li><li><a href=\"#conclusion\">Conclusion<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"deploying-an-application-on-kubernetes-cluster\">Deploying an Application on Kubernetes Cluster<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"getting-started-with-kubernetes\">Getting Started with Kubernetes<\/h3>\n\n\n\n<p>Before you can proceed, you can check out our other tutorials on getting started with Kubernetes;<\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/introduction-to-kubernetes-what-is-it-and-why-do-you-need-it\/\" target=\"_blank\" rel=\"noreferrer noopener\">Introduction to Kubernetes: What is it and why do you need it?<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/kubernetes-architecture-a-high-level-overview-of-kubernetes-cluster-components\/\" target=\"_blank\" rel=\"noreferrer noopener\">Kubernetes Architecture: A High-level Overview of Kubernetes Cluster Components<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/what-are-the-core-concepts-in-kubernetes\/\" target=\"_blank\" rel=\"noreferrer noopener\">What are the core concepts in Kubernetes?<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"setup-kubernetes-cluster\">Setup Kubernetes Cluster<\/h3>\n\n\n\n<p>Ensure you have a running Kubernetes cluster. You can check this guide below on how to deploy a Kubernetes cluster using <strong><code>kubeadm<\/code><\/strong> command.<\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/setup-kubernetes-cluster-on-ubuntu\/\" target=\"_blank\" rel=\"noreferrer noopener\">Setup Kubernetes Cluster on Ubuntu 22.04\/20.04<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"create-a-docker-container-image\">Create a Docker Container Image<\/h3>\n\n\n\n<p>Kubernetes is a container orchestration tool. Therefore before you can deploy your application in Kubernetes, you need to have packaged it in a container image.<\/p>\n\n\n\n<p>You can create your own custom image or simply just use already existing images on Docker hub to deploy your application.<\/p>\n\n\n\n<p>In this guide, we will demonstrate how to deploy an application on Kubernetes cluster using a Nagios core container image that we created before while demonstrating <a href=\"https:\/\/kifarunix.com\/deploy-nagios-as-a-docker-container\/#create-and-build-nagios-core-docker-image\" target=\"_blank\" rel=\"noreferrer noopener\">how to deploy Nagios core as Docker container<\/a>.<\/p>\n\n\n\n<p>The image was created and pushed to local image registry configured with <a href=\"https:\/\/docs.docker.com\/registry\/insecure\/#use-self-signed-certificates\" target=\"_blank\" rel=\"noreferrer noopener\">self-signed SSL\/TLS certificates<\/a>.<\/p>\n\n\n\n<p>For example, let&#8217;s get a list of images on the local registry created using the command below (<em>executed on K8s master node<\/em>);<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install jq -y<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -sk https:\/\/registry.kifarunix-demo.com\/v2\/_catalog | jq<\/code><\/pre>\n\n\n\n<p>sample output;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"repositories\": &#91;\n    \"<strong>nagios-core<\/strong>\"\n  ]\n}<\/code><\/pre>\n\n\n\n<p>Check image tags;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -sk https:\/\/registry.kifarunix-demo.com\/v2\/nagios-core\/tags\/list | jq<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"name\": \"nagios-core\",\n  \"tags\": &#91;\n    \"<strong>4.4.9<\/strong>\"\n  ]\n}<\/code><\/pre>\n\n\n\n<p>Our image is named as <strong><code>nagios-core:4.4.9<\/code><\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"create-kubernetes-deployment-and-service-manifests\">Create Kubernetes Deployment and Service Manifests<\/h3>\n\n\n\n<p>A manifest is a Kubernetes application resource file either in YAML or JSON file which contains the configurations for creating, managing, and running an application in a Kubernetes cluster. Some of the resource defitions include deployments, services, ConfigMaps, Secrets, etc.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>Deployment manifest<\/code><\/strong> defines the desired state of an application, the number of replicas and any other settings required to deploy an app in Kubernetes.<\/li>\n\n\n\n<li><strong><code>Service manifest<\/code><\/strong> defines how an application is exposed and how other services or external clients can access it. <\/li>\n\n\n\n<li><strong><code>Secrets<\/code><\/strong>: can be used to store credentials.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"configure-kubernetes-cluster-to-trust-local-docker-registry-with-self-signed-ssl-certs\">Configure Kubernetes Cluster to Trust Local Docker Registry with Self Signed SSL Certs<\/h4>\n\n\n\n<p><strong>Are you using your local Docker registry to store your own Docker images?<\/strong><\/p>\n\n\n\n<p>It is a <strong>yes<\/strong> for me. In fact, with self signed SSL\/TLS certs since it is a demo environment.<\/p>\n\n\n\n<p>Thus, if this is the case for you as well, then you need to begin by ensuring that your Kubernetes cluster can be able to pull your application Docker images from your local registry. Since Kubernetes can only connect to a secured registry, I will have to configure Kubernetes itself to to trust my local registry with self-signed SSL certificates.<\/p>\n\n\n\n<p>If you are using Docker registries secured with publicly trusted CAs, this step is not necessary for you!<\/p>\n\n\n\n<p>To configure Kubernetes cluster to trust local Docker registry configured with self signed SSL\/TLS certs, then;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>On Master node, download SSL\/TLS certificates from the local registry (and let&#8217;s store them in our demo directory);<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir ~\/k8s-app-demo<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>openssl s_client -showcerts -connect \\\nregistry.kifarunix-demo.com:443 &lt;\/dev\/null 2&gt;\/dev\/null \\\n| openssl x509 -outform PEM &gt; ~\/k8s-app-demo\/registry-ca-cert.crt<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create Kubernetes Secret to use it to store the SSL\/TLS certificate. You can create this secret store from a local certificate file just downloaded above;<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>cd ~\/k8s-app-demo<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl create secret generic registry-ca-certs --from-file=registry-ca-cert.crt<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>cd ..\/<\/code><\/pre>\n\n\n\n<p>You can list secrets using;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl get secrets<\/code><\/pre>\n\n\n\n<p>Sample output;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>NAME                TYPE     DATA   AGE\nregistry-ca-certs   Opaque   1      13s<\/code><\/pre>\n\n\n\n<p>We will configure our K8s app deployment to use this certificate secret to establish a trust with the local Docker registry while pulling the image required to deploy our application.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Install the Local Registry CA Certificate on all Kubernetes cluster nodes<\/li>\n<\/ul>\n\n\n\n<p>On each and every node in the cluster, including the master node, download and install the local Docker image registry CA. This ensures a trust is established between the nodes and the local registry.<\/p>\n\n\n\n<p>You need to store this certificate on the CA certificates directory, which is <strong><code>\/usr\/local\/share\/ca-certificates<\/code><\/strong> for Ubuntu systems and <code><strong>\/etc\/pki\/ca-trust\/source\/anchors<\/strong><\/code> on CentOS and similar derivatives.<\/p>\n\n\n\n<p>Thus, on Debian\/Ubuntu<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>openssl s_client -showcerts -connect \\\nregistry.kifarunix-demo.com:443 &lt;\/dev\/null 2&gt;\/dev\/null \\\n| openssl x509 -outform PEM | sudo tee \/usr\/local\/share\/ca-certificates\/registry-ca-cert.crt<\/code><\/pre>\n\n\n\n<p>Update the CA certificates store;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo update-ca-certificates<\/code><\/pre>\n\n\n\n<p>On CentOS\/RHEL;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>openssl s_client -showcerts -connect \\\nregistry.kifarunix-demo.com:443 &lt;\/dev\/null 2&gt;\/dev\/null \\\n| openssl x509 -outform PEM | sudo tee \/etc\/pki\/ca-trust\/source\/anchors\/registry-ca-cert.crt<\/code><\/pre>\n\n\n\n<p>Update the CA certificates store;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo update-ca-trust<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Restart the Container runtime, which in this setup is <strong><code>containerd<\/code><\/strong>.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart containerd<\/code><\/pre>\n\n\n\n<p>Kubernetes should now be able to pull images from the local registry with no issues!<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"create-kubernetes-application-deployment-manifest-on-master-node\">Create Kubernetes Application Deployment Manifest on Master Node<\/h4>\n\n\n\n<p>Next, create deployment manifest for your application. This is our sample deployment for deploying Nagios core application on Kubernetes.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim ~\/k8s-app-demo\/nagios-deployment.yaml<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\napiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: nagios-core-deployment\nspec:\n  replicas: 3\n  selector:\n    matchLabels:\n      app: nagios-core\n  template:\n    metadata:\n      labels:\n        app: nagios-core\n    spec:\n      imagePullSecrets:\n        - name: registry-ca-certs\n      containers:\n        - name: nagios-core\n          image: registry.kifarunix-demo.com\/nagios-core:4.4.9\n          imagePullPolicy: Always\n          ports:\n            - containerPort: 80\n          env:\n            - name: NAGIOSADMIN_USER_OVERRIDE\n              value: \"nagiosadmin\"\n            - name: NAGIOSADMIN_PASSWORD_OVERRIDE\n              value: \"password\"\n<\/code><\/pre>\n\n\n\n<p>Update the file accordingly, save and exit.<\/p>\n\n\n\n<p>So, what are some of the fields mean? Read more on <a href=\"https:\/\/kubernetes.io\/docs\/reference\/kubernetes-api\/workload-resources\/deployment-v1\/\" target=\"_blank\" rel=\"noopener\">Kubernetes API Reference<\/a>.<\/p>\n\n\n\n<p>When you feel like all is good to go, proceed to apply the application deployment manifest.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl apply -f ~\/k8s-app-demo\/nagios-deployment.yaml<\/code><\/pre>\n\n\n\n<p>You can display information about the Deployment using the commands:<\/p>\n\n\n\n<p>List deployments;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl get deployments<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>NAME                     READY   UP-TO-DATE   AVAILABLE   AGE\nnagios-core-deployment   3\/3     3            3           15s<\/code><\/pre>\n\n\n\n<p>Or specific deployment;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl get deployments &lt;name&gt;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl describe deployments nagios-core-deployment<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\nName:                   nagios-core-deployment\nNamespace:              default\nCreationTimestamp:      Sun, 21 May 2023 10:30:21 +0000\nLabels:                 <none>\nAnnotations:            deployment.kubernetes.io\/revision: 1\nSelector:               app=nagios-core\nReplicas:               3 desired | 3 updated | 3 total | 0 available | 3 unavailable\nStrategyType:           RollingUpdate\nMinReadySeconds:        0\nRollingUpdateStrategy:  25% max unavailable, 25% max surge\nPod Template:\n  Labels:  app=nagios-core\n  Containers:\n   nagios-core:\n    Image:      registry.kifarunix-demo.com\/nagios-core:4.4.9\n    Port:       80\/TCP\n    Host Port:  0\/TCP\n    Environment:\n      NAGIOSADMIN_USER_OVERRIDE:      nagiosadmin\n      NAGIOSADMIN_PASSWORD_OVERRIDE:  password\n    Mounts:                           <none>\n  Volumes:                            <none>\nConditions:\n  Type           Status  Reason\n  ----           ------  ------\n  Available      False   MinimumReplicasUnavailable\n  Progressing    True    ReplicaSetUpdated\nOldReplicaSets:  <none>\nNewReplicaSet:   nagios-core-deployment-694b75b55b (3\/3 replicas created)\nEvents:\n  Type    Reason             Age   From                   Message\n  ----    ------             ----  ----                   -------\n  Normal  ScalingReplicaSet  20s   deployment-controller  Scaled up replica set nagios-core-deployment-694b75b55b to 3\n<\/code><\/pre>\n\n\n\n<p>List the Pods;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl get pods<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\nNAME                                      READY   STATUS    RESTARTS   AGE\nnagios-core-deployment-77c4b8ddd5-jqtb9   1\/1     Running   0          110s\nnagios-core-deployment-77c4b8ddd5-xklk4   1\/1     Running   0          110s\nnagios-core-deployment-77c4b8ddd5-xsbhg   1\/1     Running   0          110s\n<\/code><\/pre>\n\n\n\n<p>You can get more information about each pod using the <code><strong>kubectl describe pod<\/strong><\/code> command;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl describe pod nagios-core-deployment-694b75b55b-845mh<\/code><\/pre>\n\n\n\n<p>This gives you quite information about the Pods and containers in it;<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>\nName:             nagios-core-deployment-694b75b55b-845mh\nNamespace:        default\nPriority:         0\nService Account:  default\nNode:             node02\/192.168.56.130\nStart Time:       Sun, 21 May 2023 10:30:22 +0000\nLabels:           app=nagios-core\n                  pod-template-hash=694b75b55b\nAnnotations:      cni.projectcalico.org\/containerID: e5b22e41af92435bd1fb95aae196a4374502052479705954c07e5a54b02c6ec3\n                  cni.projectcalico.org\/podIP: 10.100.140.67\/32\n                  cni.projectcalico.org\/podIPs: 10.100.140.67\/32\nStatus:           Running\nIP:               10.100.140.67\nIPs:\n  IP:           10.100.140.67\nControlled By:  ReplicaSet\/nagios-core-deployment-694b75b55b\nContainers:\n  nagios-core:\n    Container ID:   containerd:\/\/d31c41d4df5f8c84b8d5a77c4b92b40918d42b0ea48fc538ac581c6069c92396\n    Image:          registry.kifarunix-demo.com\/nagios-core:4.4.9\n    Image ID:       registry.kifarunix-demo.com\/nagios-core@sha256:fbd31bf11ab746de4437c93c2ce5e99b7acaa39d49a169a78616675c62de8d70\n    Port:           80\/TCP\n    Host Port:      0\/TCP\n    State:          Running\n      Started:      Sun, 21 May 2023 10:30:53 +0000\n    Ready:          True\n    Restart Count:  0\n    Environment:\n      NAGIOSADMIN_USER_OVERRIDE:      nagiosadmin\n      NAGIOSADMIN_PASSWORD_OVERRIDE:  password\n    Mounts:\n      \/var\/run\/secrets\/kubernetes.io\/serviceaccount from kube-api-access-hbw4f (ro)\nConditions:\n  Type              Status\n  Initialized       True \n  Ready             True \n  ContainersReady   True \n  PodScheduled      True \nVolumes:\n  kube-api-access-hbw4f:\n    Type:                    Projected (a volume that contains injected data from multiple sources)\n    TokenExpirationSeconds:  3607\n    ConfigMapName:           kube-root-ca.crt\n    ConfigMapOptional:       <nil>\n    DownwardAPI:             true\nQoS Class:                   BestEffort\nNode-Selectors:              <none>\nTolerations:                 node.kubernetes.io\/not-ready:NoExecute op=Exists for 300s\n                             node.kubernetes.io\/unreachable:NoExecute op=Exists for 300s\nEvents:\n  Type    Reason     Age   From               Message\n  ----    ------     ----  ----               -------\n  Normal  Scheduled  73s   default-scheduler  Successfully assigned default\/nagios-core-deployment-694b75b55b-845mh to node02\n  Normal  Pulling    72s   kubelet            Pulling image \"registry.kifarunix-demo.com\/nagios-core:4.4.9\"\n  Normal  Pulled     42s   kubelet            Successfully pulled image \"registry.kifarunix-demo.com\/nagios-core:4.4.9\" in 29.83093282s (29.830957408s including waiting)\n  Normal  Created    42s   kubelet            Created container nagios-core\n  Normal  Started    42s   kubelet            Started container nagios-core\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"create-kubernetes-application-service-manifest-on-master-node\">Create Kubernetes Application Service Manifest on Master Node<\/h4>\n\n\n\n<p>As already mentioned, <strong><code>service manifest<\/code><\/strong> defines how an application is exposed and how other services or external clients can access it.<\/p>\n\n\n\n<p>There are different ways in which an application can be exposed. Some of these include;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>ClusterIP<\/code><\/strong>&nbsp;&#8211; This is the default type of service and exposes the application on an internal IP address in the cluster. This type of service is only reachable from within the cluster.<\/li>\n\n\n\n<li><strong><code>NodePort<\/code><\/strong>&nbsp;&#8211; This type of service exposes the application on the same port of each selected Node in the cluster using NAT. This makes the service accessible from outside the cluster using&nbsp;<code>&lt;NodeIP&gt;:&lt;NodePort&gt;<\/code>. The default NodePort range is 30000-32767.<\/li>\n\n\n\n<li><strong><code>LoadBalancer<\/code><\/strong>&nbsp;&#8211; This type of service creates an external load balancer in the current cloud (if supported) and assigns a fixed, external IP to the service. This makes the service accessible from outside the cluster using the external IP address. The external IP address is assigned by the cloud provider and is not managed by Kubernetes.<\/li>\n<\/ul>\n\n\n\n<p>Here is our sample application service manifest;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim ~\/k8s-app-demo\/nagios-service.yaml<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\napiVersion: v1\nkind: Service\nmetadata:\n  name: nagios-core-service\nspec:\n  type: NodePort\n  selector:\n    app: nagios-core\n  ports:\n    - name: http\n      port: 80\n      targetPort: 80\n      nodePort: 30000  # Choose an available port number\n<\/code><\/pre>\n\n\n\n<p>This means Service named &#8220;nagios-core-service&#8221; selects Pods with the label &#8220;app: nagios-core&#8221; and exposes it on port 80 (<strong><code>port: 80<\/code><\/strong>). This service will be access via any cluster node IP on port 30000\/tcp.<\/p>\n\n\n\n<p>Update the file, save and exit and apply it as follows;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl apply -f ~\/k8s-app-demo\/nagios-service.yaml<\/code><\/pre>\n\n\n\n<p>List services;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl get services<\/code><\/pre>\n\n\n\n<p>Or simply;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl get svc<\/code><\/pre>\n\n\n\n<pre class=\"scroll-sz\"><code>\nNAME                  TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE\nkubernetes            ClusterIP   10.96.0.1        &lt;none>        443\/TCP        15h\nnagios-core-service   NodePort    10.101.213.238   &lt;none>        80:30000\/TCP   6s\n<\/code><\/pre>\n\n\n\n<p>Get more details about the service;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl describe service nagios-core-service<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\nName:                     nagios-core-service\nNamespace:                default\nLabels:                   <none>\nAnnotations:              <none>\nSelector:                 app=nagios-core\nType:                     NodePort\nIP Family Policy:         SingleStack\nIP Families:              IPv4\nIP:                       10.101.213.238\nIPs:                      10.101.213.238\nPort:                     http  80\/TCP\nTargetPort:               80\/TCP\nNodePort:                 http  30000\/TCP\nEndpoints:                10.100.140.67:80,10.100.186.195:80,10.100.196.131:80\nSession Affinity:         None\nExternal Traffic Policy:  Cluster\nEvents:                   <none>\n<\/code><\/pre>\n\n\n\n<p>You should now be able to access the service via any cluster node;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl get nodes -o wide<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\nNAME     STATUS   ROLES           AGE   VERSION   INTERNAL-IP      EXTERNAL-IP   OS-IMAGE           KERNEL-VERSION      CONTAINER-RUNTIME\nmaster   Ready    control-plane   15h   v1.27.2   192.168.56.110   <none>        Ubuntu 22.04 LTS   5.15.0-27-generic   containerd:\/\/1.6.21\nnode01   Ready    <none>          15h   v1.27.2   192.168.56.120   <none>        Ubuntu 22.04 LTS   5.15.0-27-generic   containerd:\/\/1.6.21\nnode02   Ready    <none>          15h   v1.27.2   192.168.56.130   <none>        Ubuntu 22.04 LTS   5.15.0-27-generic   containerd:\/\/1.6.21\nnode03   Ready    <none>          15h   v1.27.2   192.168.56.140   <none>        Ubuntu 22.04 LTS   5.15.0-27-generic   containerd:\/\/1.6.21\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"checking-kubernetes-pods-containers-logs\">Checking Kubernetes Pods\/Containers Logs<\/h4>\n\n\n\n<p>If you want to check your Kubernetes Pods\/container logs;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Run the command below to get the Pods names;<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl get pods<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Check the logs of the pod using <strong><code>kubectl logs &lt;pod-name&gt;<\/code><\/strong>.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl logs nagios-core-deployment-694b75b55b-845mh<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Check logs for specific container in a Pod<\/li>\n<\/ul>\n\n\n\n<p>First get a list of containers in a pod using the command;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl get pods &lt;pod-name&gt; -o jsonpath='{range .spec.containers&#91;*]}{.name}{\"\\n\"}{end}'.<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl get pods nagios-core-deployment-694b75b55b-845mh -o jsonpath='{range .spec.containers&#91;*]}{.name}{\"\\n\"}{end}'.<\/code><\/pre>\n\n\n\n<p>Thus, to check logs for specific container in a Pod, use the command <strong><code>kubectl logs &lt;pod-name&gt; -c &lt;container-name&gt;<\/code><\/strong>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl logs nagios-core-deployment-694b75b55b-845mh -c nagios-core<\/code><\/pre>\n\n\n\n<p>Read more on;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl logs --help<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"login-to-specific-kubernetes-pod-or-container-in-a-pod\">Login to Specific Kubernetes Pod or Container in a Pod<\/h4>\n\n\n\n<p>Just like how you do <code><strong>docker exec -it &lt;container&gt; [sh|bash]<\/strong><\/code> in Docker, you can also login as;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl exec -it &lt;pod-name&gt; -- bash<\/code><\/pre>\n\n\n\n<p>To login to specific Kubernetes Pod container;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl exec -it &lt;pod-name&gt; -c &lt;container-name&gt; -- bash<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"accessing-kubernetes-application\">Accessing Kubernetes Application<\/h3>\n\n\n\n<p>Now that our application is running on the Kubernetes cluster, you should now be able to access outside the cluster via any cluster node on port 30000. e.g http:\/\/&lt;node01&gt;:3000<\/p>\n\n\n\n<div><a href=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/05\/accessing-k8s-app.png\" class=\"td-modal-image\"><figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1485\" height=\"553\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/05\/accessing-k8s-app.png\" alt=\"Step-by-Step Guide on Deploying an Application on Kubernetes Cluster\" class=\"wp-image-16763\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/05\/accessing-k8s-app.png?v=1684668076 1485w, https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/05\/accessing-k8s-app-768x286.png?v=1684668076 768w\" sizes=\"(max-width: 1485px) 100vw, 1485px\" \/><\/figure><\/a><\/div>\n\n\n\n<p>And our Nagios Core app is now running on Kubernetes cluster.<\/p>\n\n\n\n<div><a href=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/05\/nagios-core-on-kubernetes-cluster.png\" class=\"td-modal-image\"><figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1885\" height=\"701\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/05\/nagios-core-on-kubernetes-cluster.png\" alt=\"Step-by-Step Guide on Deploying an Application on Kubernetes Cluster\" class=\"wp-image-16764\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/05\/nagios-core-on-kubernetes-cluster.png?v=1684668093 1885w, https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/05\/nagios-core-on-kubernetes-cluster-768x286.png?v=1684668093 768w, https:\/\/kifarunix.com\/wp-content\/uploads\/2023\/05\/nagios-core-on-kubernetes-cluster-1536x571.png?v=1684668093 1536w\" sizes=\"(max-width: 1885px) 100vw, 1885px\" \/><\/figure><\/a><\/div>\n\n\n\n<p>And that is pretty much it on deploying an Application on Kubernetes Cluster.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h3>\n\n\n\n<p>You have so far learnt how to;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create a Kubernetes application declarative deployment manifest<\/li>\n\n\n\n<li>Configure Kubernetes cluster to trust local Docker registry configured with self signed SSL certs.<\/li>\n\n\n\n<li>Expose Kubernetes Cluster for external access via service manifest.<\/li>\n\n\n\n<li>Check Kubernetes Pods\/Container logs<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we will provide you with a step-by-step guide on deploying an application on Kubernetes cluster. Kubernetes is the de facto container orchestration<\/p>\n","protected":false},"author":10,"featured_media":16767,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[1076,1077,121,1668],"tags":[6765,6764,6761,6768,6763,6766,6762,6767,6760],"class_list":["post-16403","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-containers","category-docker","category-howtos","category-kubernetes","tag-check-kubernetes-container-logs","tag-configure-kubernetes-to-trust-local-registry-self-signed-ssl","tag-deploy-an-app-on-kubernetes","tag-deploy-sample-application-in-kubernetes","tag-k8s-run-first-app","tag-kubectl-create-deployment-command","tag-kubernetes-deploy-an-app","tag-kubernetes-deployment-example","tag-step-by-step-guide-on-deploying-an-application-on-kubernetes-cluster","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/16403"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=16403"}],"version-history":[{"count":22,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/16403\/revisions"}],"predecessor-version":[{"id":20748,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/16403\/revisions\/20748"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/16767"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=16403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=16403"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=16403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}