Wednesday, 29 April 2020

k8s pod ??

A pod is the smallest object model that you can create and run. You can add labels to a pod to identify a subset to run operations on. When you are ready to scale your app, you can use the label to tell Kubernetes which Pod you need to scale. 
A pod typically represents a process in your cluster. Pods contain at least one container that runs the job and additionally might have other containers in it called sidecars for monitoring, logging, and so on. Essentially, a pod is a group of containers.

$ kubectl (create|get|apply|delete) -f Resource.yaml

Kubernetes resource model



  • Config maps: holds configuration data for pods to consume
  • Daemon sets: ensures that each node in the cluster runs this pod
  • Deployments: defines a desired state of a deployment object
  • Events: provides life cycle events on pods and other deployment objects
  • Endpoints: allows an inbound connections to reach the cluster services
  • Ingress: a collection of rules that allows inbound connections to reach the cluster services
  • Jobs: creates one or more pods and when they complete successfully, the job is marked as completed
  • Node: a worker machine in Kubernetes
  • Namespaces: multiple virtual clusters backed by the same physical cluster
  • Pods: the smallest deployable units of computing that can be created and managed in Kubernetes
  • Persistent volumes: provides an API for users and administrators to abstract details about how storage is provided from how it is consumed
  • Replica sets: ensures that a specified number of pod replicas are running at any given time
  • Secrets: holds sensitive information, such as passwords, OAuth tokens, and SSH keys
  • Service accounts: provides an identity for processes that run in a pod
  • Services: an abstraction that defines a logical set of pods and a policy by which to access them, sometimes called a microservice
  • Stateful sets: the workload API object that manages stateful applications

Sunday, 26 April 2020

Command to leave docker swarm

$ docker swarm leave --force

docker update the state of your service by using the command

docker service update

Update docker service with an updated number of replicas.

docker service update --replicas=5 --detach=true [servicename]

verify docker swarm node cluster


docker node ls

To add a worker to this docker swarm

docker swarm join \
    --token **** \
    10.0.120.3:2377

Initialize the docker swarm


docker swarm init --advertise-addr eth0

Check layers of docker image


docker image history [imagename]

Inspect changes to files or directories on a container’s filesystem

docker diff container-id

the docker push command to push your image to the Docker Hub registry:

docker push [dockerhub username]/[image name]

Tag the image with your username.

The Docker Hub naming convention is to tag your image with [dockerhub username]/[image name]. To do this, tag your previously created image python-hello-world to fit that format.

$ docker tag python-hello-world [dockerhub username]/python-hello-world

Log in to the Docker registry account by entering docker login on your terminal


$ docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: 

Saturday, 18 April 2020

python class __ or private class component



When any class component has a name starting with two underscores (__), it becomes private - this means that it can be accessed only from within the class.

python find length of stack

class Stack:
    def __init__(self):
        self.stackList = [1,2,3]

stackObject = Stack()
print(len(stackObject.stackList))

Python Stack as class



class Stack:    # defining the Stack class
    def __init__(self):    # defining the constructor function
        print("Hi!")

stackObject = Stack()    # instantiating the object

Python Stack push() pop()



stack = []

def push(val):
    stack.append(val)


def pop():
    val = stack[-1]
    del stack[-1]
    return val

push(3)
push(2)
push(1)

print(pop())
print(pop())
print(pop())

Thursday, 16 April 2020

Wednesday, 15 April 2020

Python Multiprocessing : Run Code in Parallel Using the Multiprocessing Module

import concurrent.futures
import time
start = time.perf_counter()
def do_something(seconds):
print(f'Sleeping {seconds} second(s)...')
time.sleep(seconds)
return f'Done Sleeping...{seconds}'
with concurrent.futures.ProcessPoolExecutor() as executor:
secs = [5, 4, 3, 2, 1]
results = executor.map(do_something, secs)
# for result in results:
# print(result)
finish = time.perf_counter()
print(f'Finished in {round(finish-start, 2)} second(s)')

Python Threading : Run Code Concurrently Using the Threading Module

import concurrent.futures import time start = time.perf_counter() def do_something(seconds): print(f'Sleeping {seconds} second(s)...') time.sleep(seconds) return f'Done Sleeping...{seconds}' with concurrent.futures.ThreadPoolExecutor() as executor: secs = [5, 4, 3, 2, 1] results = executor.map(do_something, secs) # for result in results: # print(result) # threads = [] # for _ in range(10): # t = threading.Thread(target=do_something, args=[1.5]) # t.start() # threads.append(t) # for thread in threads: # thread.join() finish = time.perf_counter() print(f'Finished in {round(finish-start, 2)} second(s)')

Thursday, 9 April 2020

python Math Function

import math

def sin(x):
    if 2 * x == pi:
        return 0.99999999
    else:
        return None

pi = 3.14

print(sin(pi/2))
print(math.sin(math.pi/2))

Git

1 git add ↳ It lets you add changes from the working directory into the staging area 2 git commit ↳ It lets you save a snapshot of currently...