2024-07-21
Mastering Kubernetes Python Library: Installation, Configuration, And Pods Listing Examples

k8s python api library

install the official library with pip install kubernetes


the default api config path for k8s is at ~/.kube/config

k3s is at /etc/rancher/k3s/k3s.yaml

microk8s is at /var/snap/microk8s/current/credentials/kubelet.config

you can also set KUBECONFIG environment variable to let kubernetes python library know where the config is


to use it:

https://github.com/kubernetes-client/python/blob/master/kubernetes/README.md

1
2
3
4
5
6
7
8
9
10
from kubernetes import client, config
# Configs can be set in Configuration class directly or using helper utility
config_path = ...
config.load_kube_config(config_path)
v1 = client.CoreV1Api()
print("Listing pods with their IPs:")
ret = v1.list_pod_for_all_namespaces(watch=False)
for i in ret.items:
print("%s\t%s\t%s" % (i.status.pod_ip, i.metadata.namespace, i.metadata.name))

Read More

2023-12-21
Waydroid Installation Steps

cursed by the wall.

install waydroid package (for ubuntu)

visit and save https://repo.waydro.id/ as waydroid_init_repo.sh, https://repo.waydro.id/waydroid.gpg as waydroid.gpg (using proxy)

comment out the download part in waydroid_init_repo.sh

1
2
# curl --progress-bar --proto '=https' --tlsv1.2 -Sf https://repo.waydro.id/waydroid.gpg --output /usr/share/keyrings/waydroid.gpg

move waydroid.gpg to /usr/share/keyrings/waydroid.gpg

execute sudo bash waydroid_init_repo.sh to setup waydroid repository

on ubuntu you need to use proxy during apt mirror syncing.

to setup proxy (relay local proxy to host):

1
2
3
4
proxy --port <port> --host <host> \
--plugins proxy.plugin.ProxyPoolPlugin \
--proxy-pool localhost:<local_proxy_port>

to use proxy:

1
2
3
sudo env https_proxy=http://<host>:<port> http_proxy=http://<host>:<port> all_proxy=http://<host>:<port> apt update
sudo env https_proxy=http://<host>:<port> http_proxy=http://<host>:<port> all_proxy=http://<host>:<port> apt install waydroid -y

after installation you should comment out the mirror at: /etc/apt/sources.list.d/waydroid.list

initialize waydroid

start waydroid service: sudo systemctl enable --now waydroid-container

the download speed of sourceforge is very slow, unless you use mirror like liquidtelecom

modify the file /usr/lib/waydroid/tools/helpers/http.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
## added part
def is_sourceforge_download_url(url: str):
keywords = ["sourceforge.net", "download"]
return all([kw in url for kw in keywords])
def use_liquidtelecom_mirror(url: str):
# example: https://sourceforge.net/projects/waydroid/files/images/system/lineage/waydroid_x86_64/lineage-18.1-20231216-VANILLA-waydroid_x86_64-system.zip/download
# -> https://sourceforge.net/projects/waydroid/files/images/system/lineage/waydroid_x86_64/lineage-18.1-20231216-VANILLA-waydroid_x86_64-system.zip/download?use_mirror=liquidtelecom
keyword = "use_mirror=liquidtelecom"
if is_sourceforge_download_url(url):
if keyword not in url:
conn_symbol = "?" if "?" not in url else "&"
url += conn_symbol + keyword
return url
## modified part
def download(args, url, prefix, cache=True, loglevel=logging.INFO, allow_404=False):
...
url = use_liquidtelecom_mirror(url)
...
...

restart service: sudo systemctl restart waydroid-container

run command sudo waydroid init

run waydroid in xorg

install weston: apt install weston

configure weston at ~/.config/weston.ini

1
2
3
[core]
xwayland=true

run weston, launch terminal at top left corner, run waydroid

network issue

in addition to the official guide, you also need to enable firewalld or ufw to make it work.

the wifi switch is irrelevant to network. it won’t be turned on.

Read More

2023-11-05
Home Assistant Installation & Setups

Fully functional HA mainly comes into two forms: flashable supervised .iso images, and virtual machines (not docker container).

Remember to create backup of HA after successful initialization. You can create an iso for the entire disk or just using backup utility builtin.

Supervisor need to be updated before other components. It is also the troublemaker. Set auto update of supervisor to false by:

1
2
ha supervisor options --auto-update=false

Since its heavy reliance on docker and github, one need to use OpenClash along with OpenWrt flashed in one dedicated router like NanoPi R2S to smooth the installation process.

Use video capture card and OBS studio to observe the RPI terminal. Attach to keyboard to type commands.

ha banner sometimes resolves issues.

To prevent addon installation limits, you can enter debug mode, edit the following file /mnt/data/supervisor/jobs.json into:

1
2
3
4
5
6
{
"ignore_conditions": [
"healthy"
]
}

Some files like /etc/docker/daemon.json, /etc/hosts cannot be changed after boot. You can change them before boot using card reader.

Read More