[k8s] 建立使用者及namespace

建立namespaces

kubectl create ns slanla

建立user

kubectl -n tw-sgis create sa slanla

RBAC 授權

建立規則

cat <<EOF > slanla-user-role.yml
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  namespace: tw-sgis
  name: slanla-user-pod
rules:
- apiGroups: ["*"]
  resources: ["pods", "pods/log"]
  verbs: ["get", "watch", "list", "update", "create", "delete"]
EOF
kubectl apply -f slanla-user-role.yml

授權對象

kubectl create rolebinding slanla-view-pod \
  --role=slanla-user-pod \
  --serviceaccount=tw-sgis:slanla \
  --namespace=tw-sgis

產生設定檔

取得 secret 資訊

SECRET=$(kubectl -n tw-sgis get sa slanla -o go-template='{{range .secrets}}{{.name}}{{end}}')

設定API Server

API_SERVER="https://xxx.xxx.xxx.xxx:6443"

取得 ca

CA_CERT=$(kubectl -n tw-sgis get secret ${SECRET} -o yaml | awk '/ca.crt:/{print $2}')

建立

cat <<EOF > slanla.conf
apiVersion: v1
kind: Config
clusters:
- cluster:
    certificate-authority-data: $CA_CERT
    server: $API_SERVER
  name: cluster
EOF

取得token

TOKEN=$(kubectl -n tw-sgis get secret ${SECRET} -o go-template='{{.data.token}}')

設定 token

kubectl config set-credentials slanla-user \
  --token=`echo ${TOKEN} | base64 -d` \
  --kubeconfig=slanla.conf

建立context: default

kubectl config set-context default \
  --cluster=cluster \
  --user=slanla-user \
  --kubeconfig=slanla.conf

指定context: default

kubectl config use-context default \
  --kubeconfig=slanla.conf

centsos 基本安裝參考指令

#更新
yum update -y && yum autoremove -y

#安裝常用工具,如vim/wget/openssh-server/nslookup/ping/ifconfig
yum install -y git vim wget openssh* nfs-utils nfs-utils-lib open-vm-tools net-tools bind-utils iputils yum-utils

#設定ssh
mkdir -p ~/.ssh
cat <<EOF > ~/.ssh/config
Host *
    StrictHostKeyChecking no
EOF

#關閉swap
SWAPLINE=$(cat /etc/fstab | grep swap | awk '{print $1}' | sed 's/\//\\\//g')
sed -i "s/$SWAPLINE/#$SWAPLINE/g" /etc/fstab 
swapoff -a
free -m

#關閉SELINUX
setenforce 0
sed -i s/^SELINUX=.*$/SELINUX=disabled/ /etc/selinux/config
systemctl disable firewalld.service
systemctl disable libvirtd.service

#Forward Policy
iptables -P FORWARD ACCEPT

#關閉防火牆
iptables -P FORWARD ACCEPT
systemctl stop firewalld
systemctl disable firewalld

#NTP校時
yum install ntp ntpdate ntp-doc -y
cat > /etc/ntp.conf  <<EOL
restrict 127.0.0.1
restrict ::1
server time.stdtime.gov.tw  minpoll 1 maxpoll 3
server tock.stdtime.gov.tw  minpoll 2 maxpoll 3
server watch.stdtime.gov.tw minpoll 3 maxpoll 4
server clock.stdtime.gov.tw minpoll 4 maxpoll 5
server tick.stdtime.gov.tw  minpoll 5 maxpoll 6
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor
EOL

systemctl stop ntpd
ntpdate time.stdtime.gov.tw
systemctl enable ntpd
systemctl start ntpd
ntpq -p

miniconda 安裝

安裝 miniconda

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -O ~/miniconda.sh
bash ~/miniconda.sh -b -p $HOME/miniconda

路徑設定

echo 'PATH="$HOME/miniconda/bin:$PATH"' >> ~/.bash_profile 
chmod +x ~/.bash_profile
PATH="$HOME/miniconda/bin:$PATH"

chmod 設定權限

設定test資料夾下的所有檔案權限

find test -type f -exec chmod 644 {} +

設定test資料夾下的所有資料夾權限

find test -type d -exec chmod 755 {} +

Ubuntu 16.04 架設HylaFAX筆記

1.首先需要一個USB Modem以及一台Ubuntu(這邊是在iMac下用Parallels Desktop跑Ubuntu 16.04)

2.設定ttyACM相關權限
編輯udev

sudo vim /etc/udev/rules.d/70-ttyusb.rules

加入下面設定:

KERNEL=="ttyUSB[0-9]*",MODE="0666"
KERNEL=="ttyACM[0-9]*",MODE="0666"

以及透過chmod修改權限

sudo chmod o+rw /dev/ttyS0

3.安裝

sudo apt-get update
DEBIAN_FRONTEND=noninteractive sudo apt-get install -y cu hylafax-server hylafax-client

4.測試USB Modem

sudo cu -l ttyS0

出現connected.既可按兩下“.離開

5.設定HylaFAX

sudo faxsetup

6.設定撥號前按下0

sudo vim  /var/spool/hylafax/etc/config.ttyACM0 

修改ModemDialCmd設定:

ModemDialCmd:           ATX3D0T%s       # press 0 before dialing

7.傳真a.pdf至11223344

sendfax -n -d 11223344 a.pdf

8.查看

#歷史狀態
faxstat -d
#接收狀態
faxstat -r
#傳送狀態
faxstat -s

9.刪除job 1

faxrm 1

10.清除所有傳送資料(如果隔一陣子想要清除所有傳送資料的話)

sudo service hylafax stop
sudo rm -rf /var/spool/hylafax/docq/*
sudo rm -rf /var/spool/hylafax/doneq/*
sudo rm -rf /var/spool/hylafax/info/*
sudo rm -rf /var/spool/hylafax/log/*
sudo rm -rf /var/spool/hylafax/sendq/*
sudo service hylafax restart
faxstat -d

install nodejs on macos with nvm

#安裝nvm
brew install nvm

#設定路徑
echo "source $(brew --prefix nvm)/nvm.sh" >> ~/.bash_profile
. ~/.bash_profile

#查看版本
nvm ls-remote

#安裝8.x
nvm install v8.15.1

#顯示已安裝版本
nvm ls

#切換版本
nvm use v8.15.1

#設定PATH
echo "PATH=$PATH:$(dirname $(nvm which v8.15.1))" >> ~/.bash_profile
. ~/.bash_profile

install docker 18.06 on raspberry pi

最近在raspberry pi上面安裝docker 18.09後,
會發生無法啟動docker的問題.
因此需要降版至18.06,語法如下:

sudo apt-mark unhold docker-ce
sudo apt-get purge -y docker-ce
sudo apt-get autoremove -y --purge docker-ce
sudo apt-get autoclean
sudo rm -rf /var/lib/docker
export VERSION=18.06 && curl -sSL get.docker.com | sh
sudo apt-mark hold docker-ce