Namespace Cheat Sheet

Here’s a basic cheat sheet for working with namespaces in various contexts, such as programming languages, container orchestration, and networking:

Programming Languages (e.g., Python)

Creating a Namespace:

my_namespace = {}

Adding Variables to a Namespace:

my_namespace.variable_name = "value"

Accessing Variables in a Namespace:

print(my_namespace.variable_name)

Linux Namespace

Viewing Existing Namespaces:

ip netns list

Creating a Network Namespace:

ip netns add namespace_name

Running a Command in a Namespace:

ip netns exec namespace_name command

Kubernetes Namespace

Creating a Namespace in Kubernetes:

kubectl create namespace my_namespace

Listing Namespaces:

kubectl get namespaces

Running a Pod in a Specific Namespace:

kubectl run my_pod --image=my_image --namespace=my_namespace

Python import Namespace

Importing a Module with Namespace:

import my_module

Accessing Functions/Variables:

my_module.my_function()

C++ Namespace

Defining a Namespace:

namespace my_namespace {
    // code
}

Using Namespace in Code:

using namespace my_namespace;

JavaScript Namespace

Creating an Object Namespace:

var myNamespace = {};

Adding Properties to Namespace:

myNamespace.variableName = "value";

Accessing Properties:

console.log(myNamespace.variableName);

Here is a dedicated JavaScript Cheat Sheet

This cheat sheet covers basic concepts related to namespaces in programming languages, Linux, Kubernetes, Python, C++, and JavaScript. Keep in mind that the usage may vary depending on the context and technology.