serving the solutions day and night

Pages

Showing posts with label kubectl. Show all posts
Showing posts with label kubectl. Show all posts

Wednesday, August 19, 2020

Deploy ASP.NET Core Application different image verison in Kubernetes

Deploying the pods (individually or with a replication controller), using the same labels, except for the version, for which you use the value v2. 

Modified the code (frontendmvc).

Build the image, re name the image tag version 2 & publish the image to Docker Hub

docker build -t frontendmvc .
docker tag frontendmvc makader/myapp:frontendmvc-v2
docker push makader/myapp:frontendmvc-v2


Monday, August 17, 2020

Kubernetes kubectl Commands

kubectl cluster-infoTo show information about the Kubernetes cluster. It's a command line tool installed with K8s that allows us to interact with a cluster





Create a Kubernetes service using a YAML

Instead of exposing directly (see the blog), create a service in a declarative way using a YAML file

forntendmvc_service .yaml

--- 
apiVersion: v1
kind: Service
metadata: 
 name: myapp-svc
spec: 
  selector:
    app:myapp
  type: NodePort
  ports:
    - port:80
      nodePort: 30001

Sunday, August 16, 2020

Access ASP.NET Core MVC Application with Kubernetes and NodePort

Execute the command "kubectl describe pod myapp-rc-wl284",  each of them is running on a specific IP, internal to the node.  

The Node IP (192.168.65.3), but you can’t access it directly because the forwarding rule to send the requests from the node IP to the pod IP is missing.

Kubernetes Service Type using -type options

The command to expose the replication controller 

kubectl expose rc myapp-rc --name=myapp-rc-service --type=NodePort

The --name option sets a name for the service. 
The --type option sets the service type, and can be one of the following four values:

  • ClusterIP: The default value that exposes the pods internal to the cluster. 
  • NodePort: Exposes the pods as a static port on each node that contains the pods
  • LoadBalancer: Exposes the pods externally using a load balancer of a cloud provider. 
  • ExternalName: Available from version 1.7 of kube-dns to expose the pods through the contents of the externalName field.

Kubernetes ReplicationController

Create multiple instances of the pod using a ReplicationController, which is a master controller that replicates the specified pods, balances them on all the nodes, and reacts if some pod dies to restore the desired state.

forntendmvc_rc.yaml 

--- 
apiVersion: v1
kind: ReplicationController
metadata: 
 name: myapp-rc
spec: 
   replicas: 5  
   selector:    
     app: myapp    
   template:    
     metadata:         
       labels:           
         app: myapp           
         zone: prod           
         version: v1        
     spec:           
       containers:             
         - name:myapp-frontendmvc              
           image: makader/myapp:frontendmvc-v1              
           ports:               
             - containerPort:80

Deploy ASP.NET Core Application images in Kubernetes (K8s) & POD

Publish the image in Docker Hub

Rename the image tag from frontendmvc:v1, to <account_username>/<repository_name>:<tag> (in our case, makdockerhub/myapp:frontendmvc-v1). 

docker tag frontendmvc makader/myapp:frontendmvc-v1

Publish the image with the docker push command. 

  docker push makader/myapp:frontendmvc-v1

 

 

Now we can deploy a frontendmvc container everywhere (aws, azure, pcf, Kubernetes,...).