Category: Kubernetes

 

Solution Kubectl exec command terminated with exit code 126

The Solution Kubectl exec command terminated with exit code 126,


>kubectl --kubeconfig="config.yaml"  exec --stdin --tty esmartpod-56c88948597-8gn8x --namespace="services" -- /bin/bash

Error:
OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused "exec: \"/bin/bash\": stat /bin/bash: no such file or directory": unknown
command terminated with exit code 126

Solution: After investigating the reason why this pod does not has a /bin/bash executable, trying with — /bin/sh instead and et voila is working


>kubectl --kubeconfig="config.yaml"  exec --stdin --tty esmartpod-56c88948597-8gn8x --namespace="services" -- /bin/sh

How to Installing s3cmd and download from S3 digitalocean on Windows

How to Installing s3cmd and download from S3 digitalocean on Windows
At the moment, there is no direct way to download the files locally or move from one space to another.
You can use tools like s3cmd to download the files and have them saved in your local repositories.
You can setup s3cmd by referring to the link given below

Installing s3cmd on Windows

https://www.digitalocean.com/docs/spaces/resources/s3cmd/

 Installing s3cmd and download from S3 digitalocean on Windows

Yes, however, being written in Python, s3cmd requires Python 2.4+
for Windows to be installed and also it requires the Python library date-util.

Step 1 Download the last version of Python
– https://www.python.org/download/releases/2.4/, I have download the version python-3.8.5 and install it
and open the CMD


 C:\Python38>python --version
Python 3.8.5

Step 2 Download and install date-util
Python recommended to this:Please install the python dateutil module:
$ sudo apt-get install python-dateutil
or
$ sudo yum install python-dateutil
or
$ pip install python-dateutil

Tying to install


C:\Python38>pip install pyton-dateutil
ERROR: Could not find a version that satisfies the requirement pyton-dateutil (from versions: none)
ERROR: No matching distribution found for pyton-dateutil
WARNING: You are using pip version 20.1.1; however, version 20.2.3 is available.
You should consider upgrading via the 'c:\python38\python.exe -m pip install --upgrade pip' command.

That was not working, you can download directly from https://pypi.org/project/python-dateutil/#files
After downloading the “python_dateutil-2.8.1-py2.py3-none-any.whl” copy to pyhon folder C:\Python38>


C:\Python38>pip install python_dateutil-2.8.1-py2.py3-none-any.whl
Processing c:\python38\python_dateutil-2.8.1-py2.py3-none-any.whl
Collecting six>=1.5
  Downloading six-1.15.0-py2.py3-none-any.whl (10 kB)
Installing collected packages: six, python-dateutil
ERROR: After October 2020 you may experience errors when installing or updating packages. This is because pip will change the way that it resolves dependency conflicts.

We recommend you use --use-feature=2020-resolver to test your packages with the new resolver before it becomes the default.

s3cmd 2.1.0 requires python-magic, which is not installed.
Successfully installed python-dateutil-2.8.1 six-1.15.0

Step 3 Download S3cmd
You can download s3cmd https://sourceforge.net/projects/s3tools/
Unzip and copy the file inside the Pyton folder


C:\Python38>python s3cmd --version
s3cmd version 2.1.0

Step 4 Initialize the Configuration File
By default, s3cmd stores its configuration file, .s3cfg, in the home directory of the user that ran the configuration
command. .s3cfg is a plain text file of key/value pairs which can be edited directly once it has been created.

4.1 Configure s3cmd


C:\Python38>python s3cmd --configure
ERROR: Option --preserve is not yet supported on MS Windows platform. Assuming --no-preserve.
ERROR: Option --progress is not yet supported on MS Windows platform. Assuming --no-progress.

Enter new values or accept defaults in brackets with Enter.
Refer to user manual for detailed description of all options.

Access key and Secret key are your identifiers for Amazon S3. Leave them empty for using the env variables.
Access Key:
Secret:

Save settings? [y/N] y
Configuration saved to ‘C:\Users\YourUsername\AppData\Roaming\s3cmd.ini’

Step 5 test connection and download files
C:\Python38>python s3cmd ls

Once s3cmd setup is done, you can use s3cmd command to download files recursively in spaces.

s3cmd sync s3://bucketnamehere/folder /destination/folder
or
s3cmd get s3://ukgoodbye/Weekly/mysales/ D:\ukgoodbye\mysales

Kubernete restart a service

Kubernete restart a service, Resource will be rollout restarted


>kubectl --kubeconfig="config.yaml"  rollout restart deployment --help

Restart a resource.

Resource will be rollout restarted.

Examples:
# Restart a deployment
kubectl rollout restart deployment/nginx

# Restart a daemonset
kubectl rollout restart daemonset/abc

Options:
–allow-missing-template-keys=true: If true, ignore any errors in templates when a field or map key is missing in
the template. Only applies to golang and jsonpath output formats.
-f, –filename=[]: Filename, directory, or URL to files identifying the resource to get from a server.
-k, –kustomize=”: Process the kustomization directory. This flag can’t be used together with -f or -R.
-o, –output=”: Output format. One of:
json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.
-R, –recursive=false: Process the directory used in -f, –filename recursively. Useful when you want to manage
related manifests organized within the same directory.
–template=”: Template string or path to template file to use when -o=go-template, -o=go-template-file. The
template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].

Usage:
kubectl rollout restart RESOURCE [options]

Use “kubectl options” for a list of global command-line options (applies to all commands).


>kubectl --kubeconfig="config.yaml"  rollout restart deployment resourcespace --namespace="ukgoodbye"

2 – Kubernetes – how to get cluster-info


Kubernetes master is running at https://c3f1d7ac-f5b8-4ad5-8102-0015099dbd3a.k8s.ondigitalocean.com
KubeDNS is running at https://c3f1d7ac-f5b8-4ad5-8102-0015099dbd3a.k8s.ondigitalocean.com/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

How to Copy Container Files from DigitalOcean, Kubernetes

Download files from Kubernetes,

Step 1 – Connect to your digitalocean
Download the configuration file
To connect to your cluster from the command line, you need a configuration file on your administration machine that contains an authentication certificate and other connection information.

Download the configuration file

Step 2 Download the kubectl
The Kubernetes command-line tool, kubectl, allows you to run commands against Kubernetes clusters.

Example:kubectl passing config de view the Persistent Volume


 kubectl --kubeconfig="config.yaml" get pv

To get namespaces


 c:\kubernetes\kubectl --kubeconfig="config.yaml" get namespaces

To get the pods by passing the namespace,get pods from a namespaces: for example “ukgoodbye”


c:\kubernetes\kubectl --kubeconfig="config.yaml" get pods --namespace="ukgoodbye"

To copy or download the content for folder name “secondliveforstuff”


 c:\kubernetes\kubectl --kubeconfig="config.yaml" cp ukgoodbye/ukgoodbye-75556b549-22rks:secondliveforstuff  c:\kubernetes\secondliveforstuff

kubectl cp

kubectl –help


S C:\> kubectl cp --help
Copy files and directories to and from containers.

Examples:
  # !!!Important Note!!!
  # Requires that the 'tar' binary is present in your container
  # image.  If 'tar' is not present, 'kubectl cp' will fail.
  #
  # For advanced use cases, such as symlinks, wildcard expansion or
  # file mode preservation consider using 'kubectl exec'.

  # Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace 
  tar cf - /tmp/foo | kubectl exec -i -n   -- tar xf - -C /tmp/bar

  # Copy /tmp/foo from a remote pod to /tmp/bar locally
  kubectl exec -n   -- tar cf - /tmp/foo | tar xf - -C /tmp/bar

  # Copy /tmp/foo_dir local directory to /tmp/bar_dir in a remote pod in the default namespace
  kubectl cp /tmp/foo_dir :/tmp/bar_dir

  # Copy /tmp/foo local file to /tmp/bar in a remote pod in a specific container
  kubectl cp /tmp/foo :/tmp/bar -c 

  # Copy /tmp/foo local file to /tmp/bar in a remote pod in namespace 
  kubectl cp /tmp/foo /:/tmp/bar

  # Copy /tmp/foo from a remote pod to /tmp/bar locally
  kubectl cp /:/tmp/foo /tmp/bar

Options:
  -c, --container='': Container name. If omitted, the first container in the pod will be chosen
      --no-preserve=false: The copied file/directory's ownership and permissions will not be preserved in the container

Usage:
  kubectl cp   [options]

Use "kubectl options" for a list of global command-line options (applies to all commands).
PS C:\Users\MoussaSow\Downloads\kubernetes>