Saturday, January 9, 2021

Install pip on Python3

https://stackoverflow.com/questions/31273157/how-to-install-pip-on-compiled-from-source-python

Custom build Python might not come with pip, so you can rebuilt with the following options:

./configure --with-openssl=/usr/local/opt/openssl --with-ensurepip=install

pip need Python ssl module, which in turn need openssl.

Or,  python get-pip.py will also install pip. again, assuming Python is build with ssl module.
Download get-pip.py via:
curl -sSL https://bootstrap.pypa.io/get-pip.py -o get-pip.py

The ensurepip package provides support for bootstrapping the pip installer into an existing Python installation or virtual environment. This bootstrapping approach reflects the fact that pip is an independent project with its own release cycle, and the latest available stable version is bundled with maintenance and feature releases of the CPython reference interpreter.

In most cases, end users of Python shouldn’t need to invoke this module directly (as pip should be bootstrapped by default), but it may be needed if installing pip was skipped when installing Python (or when creating a virtual environment) or after explicitly uninstalling pip.
python -m ensurepip

This invocation will install pip if it is not already installed, but otherwise does nothing. To ensure the installed version of pip is at least as recent as the one available in ensurepip, pass the --upgrade option:

python -m ensurepip --upgrade

By default, pip is installed into the current virtual environment (if one is active) or into the system site packages (if there is no active virtual environment).

Setting up GDB for Debugging Python 3.9.1 on OS X Mojave

https://unconj.ca/blog/setting-up-gdb-for-debugging-python-on-os-x.html

brew install gdb and codesign gdb (updated procedure from: https://sourceware.org/gdb/wiki/PermissionsDarwin)

Brew installed python3 is already in thin format, no need to use lipo to extract, although you can still use lipo to check python executable format. (Non-fat file: python3 is architecture: x86_64)

Providing python3 interpreter (not symbolic link) with path if necessary, after gdb , and this will solve error message like: "0x7ffeefbff800s": not in executable format: file format not recognized

Had to compile Python3 from source to get rid of the following warning: ( ./configure --with-pydebug). Uncommenting SSL related lines in Modules/Setup file is to load ssl module in Python

Reading symbols from python...
(No debugging symbols found in python)

Also build gdb from source code again (./configure --with-python=/usr/local/bin/python3 --disable-werror), as brew info gdb failed with Brew installed python@3.9. Codesign command again for gdb.







Python gdp support: https://devguide.python.org/gdb/

 ~/.gdbinit with content below:

set startup-with-shell off

add-auto-load-safe-path /usr/local/bin


Thursday, July 30, 2020

Jenkins ssh-agent plug in



Jenkins ssh-agent only takes user and private key as credentials for build jobs, not user and password, otherwise you will get error below:

FATAL: [ssh-agent] Could not find specified credentials
[ssh-agent] Looking for ssh-agent implementation... 
[ssh-agent] Exec ssh-agent (binary ssh-agent on a remote machine)
.....
Permission denied, please try again. 
Permission denied (publickey,password).

Target remote server must have completed setting for ssh login via private key before. (public key in ~/.ssh/authorized_keys)

Sunday, May 10, 2020

NFS Server Provisioner on K8S

Another dynamic storage provisioner from Quay. NFS server inside K8S for bare-metal/on-premise kubernetes cluster.

https://github.com/kubernetes-incubator/external-storage/tree/master/nfs

nfs-common and nfs-utils need to be installed on kubelet, otherwise error log might include: 
  • bad option; for several filesystems (e.g. nfs, cifs) you might need a /sbin/mount.<type> helper program.
  • Warning  FailedMount  24m  kubelet, MountVolume.SetUp failed for volume "pvc-2c49da00-3431-4e3c-a1cc-84d1daa4a6ab" : mount failed: exit status 32
In case there is error: pod has unbound immediate PersistentVolumeClaims, it has nothing with storage provision, which just indicates that pod does not not have storage class defined in manifest file or K8S doesn't have default storage class.

To set up default storage class in kubernetes:
  • kubectl patch storageclass storage-class-name -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'

Saturday, May 9, 2020

Jenkins on K8S

Jenkins can deploy via Rancher catalog or Helm chart.

Jenkins K8S deployment will need persistent storage. Jenkins service can be exposed or access via ingress rules.

Jenkins master -> Credentials -> add Credentials -> kind: Kubernetes Service Account
Manage Jenkins -> Manager Nodes and Cloud -> Configure Cloud (for new version of Jenkins)
  • Test Connection 
  • Pod Retention: Never (Jenkins slave pod will be terminated after build job completes)
  • Slave pod will be placed into jenkins namespace by default

Jenkins slave on K8S

Use K8S as Jenkins slave/agent via Jenkins kubernetes plugin. (continuous integration)
  • From Jenkins master, install Kubernetes plugin (This plugin integrates Jenkins with Kubernetes)
  • Credentials -> Add Credentials -> Kind: Secret file (kubeconfig file from K8S)
  • Manage Jenkins -> Manage Nodes and Cloud -> Configure Clouds (new version of Jenkins) 
  1. Credentials: select Secret file name just created from drop-down menu, and Test Connection
  2. Jenkins URL and tunnel match Jenkins master. No need https:// for tunnel
  3. Pod label will be used for slave pod label in K8S
  4. Pod Template: name will be prefix for slave pod name prefix in K8S; blank namespace will create slave pod in default namespace in K8S;
  5. Pod Template -> Labels is critical, which help Jenkins master decides which builder will be used for the build job. 
  6. Pod Template: Usage: only builds job with label expression matching this label
  7. Define container template details: name: jnlp; docker image: jenkins/jnlp-slave:latest; working directory: /home/jenkins/; also environment variable value pair: {JENKINS_URL: http://jenkins-master:8080} (or adding other agent as Pod Template)
When creating a new build job, check Restrict where this project can be run, enter Label expression: Pod template label in previous step 5, so Jenkins master will use K8S pod to execute build task.

Jenkins slave started in K8S, then terminated in K8S after build job completes with proper pod retention setting in Pod Template.


Use K8S as Jenkins slave via Jenkin Kubernetes Continuous Deploy Plugin (continuous deployment on kubernetes)
  • From Jenkins master, install Kubernetes Continuous Deploy Plugin
  • Credentials -> Add Credentials -> Kind: Kubernetes Configuration (KubeConfig); directly copy content of  kubeconfig file into textext. The ID of this Jenkins credential will match value of  kubeconfigId in file: Jenkinsfile, which is in source code Repositories, such as github, or private repository
  • If Kubernetes plugin is already configured, no more configuration is required.
When creating a new pipeline in Jenkins, in Pipeline section: select Pipeline script from SCM, then select proper SCM, repository and branch. Default script path is: Jenkinsfile

Jenkins pipeline checkout source from SCM, and start slave pod on K8S to build images and upload container images into registry such Docker hub or any private/public registry defined in Jenkinsfile from SCM. Then slave pod on K8S is terminated with the completion of Continuous Integration/Delivery process. Finally, pipeline script will deploy app Pod via manifest in Jenkinsfile, always pulling container images from registry.

Tuesday, May 5, 2020

Delete Terminating hanging namespace

clean up content in finalizer section via json/yaml file or directly edit namespace via kubectl

Methold below always works
Assuming local is terminating...
kubectl get namespace local -o json > local.json         
kubectl get namespace local -o json \
            | tr -d "\n" | sed "s/\"finalizers\": \[[^]]\+\]/\"finalizers\": []/" \
            | kubectl replace --raw /api/v1/namespaces/local/finalize -f -