解决了好几个软件的构建问题,在解决部署问题,bluemix部署

Posted jackadam

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决了好几个软件的构建问题,在解决部署问题,bluemix部署相关的知识,希望对你有一定的参考价值。

https://www.puteulanus.com/archives/838#comment-961
新版 Bluemix 一键搭建 SS 脚本


https://blog.feixueacg.com/bluemix-stop-docker/
IBM CLOUD Kubernetes 集群简易教程

磕了几天kubernetes教程,还是云里雾里。


先记录有用的东西吧

 

#!/bin/bash

# 定义参数检查
paras=[email protected]
function checkPara(){
    local p=$1
    for i in $paras; do if [[ $i == $p ]]; then return; fi; done
    false
}

# 设定区域
REGION=ng
checkPara au && REGION=au-syd # Sydney, Australia
checkPara uk && REGION=eu-gb # London, England
checkPara de && REGION=eu-de # Frankfurt, Germany

# 检查 BBR 参数
BBR=false
checkPara bbr && BBR=true

# 安装 unrar
#wget https://coding.net/u/tprss/p/bluemix-source/git/raw/master/v2/unrar
#chmod +x ./unrar
#sudo mv ./unrar /usr/bin/

# 安装 kubectl
#wget -O kubectl.rar http://detect-10000037.image.myqcloud.com/5c964783-429d-4e31-a286-6580c97d4ac1
#unrar x kubectl.rar
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl

# 安装 Bluemix CLI 及插件
#wget -O Bluemix_CLI.rar http://detect-10000037.image.myqcloud.com/8e739b20-0b11-424a-95bf-99ec00c29c4a #0.6.1
#unrar x Bluemix_CLI.rar
#cd Bluemix_CLI
#chmod +x install_bluemix_cli
#sudo ./install_bluemix_cli
#bluemix config --usage-stats-collect false
#wget -O container-service-linux-amd64.rar http://detect-10000037.image.myqcloud.com/1eb05dc4-d8ba-4347-b932-30558134d9ee
#unrar x container-service-linux-amd64.rar
#bx plugin install ./container-service-linux-amd64
wget -O Bluemix_CLI_amd64.tar.gz https://plugins.ng.bluemix.net/download/bluemix-cli/0.6.5/linux64
tar -zxf Bluemix_CLI_amd64.tar.gz
cd Bluemix_CLI
sudo ./install_bluemix_cli
bluemix config --usage-stats-collect false
bx plugin install container-service -r Bluemix

# 初始化
#echo -e -n "\n请输入用户名:"
#read USERNAME
#echo -n 请输入密码:
#read -s PASSWD
#echo -e \n
#(echo 1; echo no) | bx login -a https://api.${REGION}.bluemix.net -u $USERNAME -p $PASSWD
bx login -a https://api.${REGION}.bluemix.net
(echo 1; echo 1) | bx target --cf
bx cs init
$(bx cs cluster-config $(bx cs clusters | grep normal | awk {print $1}) | grep export)
PPW=$(openssl rand -base64 12 | md5sum | head -c12)
SPW=$(openssl rand -base64 12 | md5sum | head -c12)
AKN=del_$(openssl rand -base64 12 | md5sum | head -c5)
AK=$(bx iam api-key-create $AKN | tail -1 | awk {print $3} | base64)

# 尝试清除以前的构建环境
kubectl delete pod build 2>/dev/null
kubectl delete deploy kube ss bbr 2>/dev/null
kubectl delete svc kube ss ss-tcp ss-udp 2>/dev/null
kubectl delete rs -l run=kube | grep deleted --color=never
kubectl delete rs -l run=ss | grep deleted --color=never
kubectl delete rs -l run=bbr | grep deleted --color=never


# 等待 build 容器停止
while ! kubectl get pod build 2>&1 | grep -q "NotFound"
do
    sleep 5
done

# 创建构建环境
cat << _EOF_ > build.yaml
apiVersion: v1
kind: Pod
metadata:
  name: build
spec:
  containers:
  - name: alpine
    image: docker:dind
    command: ["sleep"]
    args: ["1800"]
    securityContext:
      privileged: true
  restartPolicy: Never
_EOF_
kubectl create -f build.yaml
sleep 3
while ! kubectl exec -it build expr 24 * 24 2>/dev/null | grep -q "576"
do
    sleep 5
done
IP=$(kubectl exec -it build -- wget -qO- whatismyip.akamai.com)
PEM=$(basename $(ls ~/.bluemix/plugins/container-service/clusters/*/*.pem))
kubectl cp ~/.bluemix/plugins/container-service/clusters/*/*.yml build:/root/config
kubectl cp ~/.bluemix/plugins/container-service/clusters/*/*.pem build:/root/"$PEM"
(echo ‘apk add --update curl ca-certificates openssl‘;     echo wget -O build.sh ‘https://gist.githubusercontent.com/anonymous/dcc43cd069ad77453768f8505f73c836/raw/e930391795ea1c7af36306b098285bb12ebc89c4/build.sh‘;     echo sh build.sh "$AKN" "$AK" "$PPW" "$SPW" "$REGION" "$IP" "$BBR" "$PEM") | kubectl exec -it build sh

# 输出信息
#PP=$(kubectl get svc kube -o=custom-columns=Port:.spec.ports\[\*\].nodePort | tail -n1)
#SP=$(kubectl get svc ss -o=custom-columns=Port:.spec.ports\[\*\].nodePort | tail -n1)
SP=443
#IP=$(kubectl get node -o=custom-columns=Port:.metadata.name | tail -n1)
wget https://coding.net/u/tprss/p/bluemix-source/git/raw/master/v2/cowsay
chmod +x cowsay
cat << _EOF_ > default.cow
\$the_cow = <<"EOC";
        \$thoughts   ^__^
         \$thoughts  (\$eyes)\\\\_______
            (__)\\       )\\\\/\\\             \$tongue ||----w |
                ||     ||
EOC
_EOF_
clear
echo
./cowsay -f ./default.cow 惊不惊喜,意不意外
echo 
echo ‘ 管理面板地址: ‘ http://$IP/$PPW/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/
echo 
echo ‘ SS:‘
echo ‘  IP: ‘$IP
echo ‘  Port: ‘$SP
echo ‘  Password: ‘$SPW
echo ‘  Method: aes-256-cfb‘
ADDR=‘ss://‘$(echo -n "aes-256-cfb:[email protected]$IP:$SP" | base64)
echo 
echo ‘  快速添加: ‘$ADDR
echo ‘  二维码: http://qr.liantu.com/api.php?text=‘$ADDR
echo 

 

 

#!/bin/sh

# 安装 docker
#yum install -y yum-utils device-mapper-persistent-data lvm2 wget openssl
#yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
#yum install docker-ce -y
dockerd >/dev/null 2>&1 &
sleep 3

# 安装 kubectl
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
chmod +x ./kubectl
mv ./kubectl /usr/local/bin/kubectl

# 安装 Bluemix CLI 及插件
wget -O Bluemix_CLI_amd64.tar.gz https://plugins.ng.bluemix.net/download/bluemix-cli/0.6.5/linux64
tar -zxf Bluemix_CLI_amd64.tar.gz
cd Bluemix_CLI
sh ./install_bluemix_cli
bluemix config --usage-stats-collect false
#bx plugin install container-service -r Bluemix

# 初始化
AKN=$1
AK=$(echo $2 | base64 -d)
PPW=$3
SPW=$4
REGION=$5
IP=$6
BBR=$7
PEM=$8
export BLUEMIX_API_KEY=$AK
(echo 1; echo no) | bx login -a https://api.${REGION}.bluemix.net
(echo 1; echo 1) | bx target --cf
#bx cs init
#$(bx cs cluster-config $(bx cs clusters | grep normal | awk {print $1}) | grep export)
bx iam api-key-delete $AKN

# 初始化镜像库
bx plugin install container-registry -r Bluemix
bx cr login
for name in $(bx cr namespace-list | grep del_); do (echo y) | bx cr namespace-rm $name; done
NS=del_$(openssl rand -base64 16 | md5sum | head -c16)
bx cr namespace-add $NS

# 构建面板容器
#cp /root/.bluemix/plugins/container-service/clusters/*/*.yml ./config
#cp /root/.bluemix/plugins/container-service/clusters/*/*.pem ./
#PEM=$(basename $(ls /root/.bluemix/plugins/container-service/clusters/*/*.pem))
cd /root/

wget -O caddy.tar.gz https://caddyserver.com/download/linux/amd64
tar -zxf caddy.tar.gz
chmod +x ./caddy

cp /usr/local/bin/kubectl ./

cat << _EOF_ > Caddyfile
0.0.0.0:80
gzip
proxy /$PPW/ 127.0.0.1:8001
_EOF_

cat << _EOF_ > run.sh
kubectl proxy --accept-hosts ‘.*‘ --api-prefix=/$PPW/ &
caddy -conf /etc/caddy/Caddyfile
_EOF_

cat << _EOF_ > Dockerfile
FROM alpine:latest
RUN apk add --update ca-certificates
ADD kubectl /usr/local/bin/
RUN mkdir /root/.kube
ADD config /root/.kube/config
ADD $PEM /root/.kube/
ADD caddy /usr/local/bin/
RUN mkdir /etc/caddy
ADD Caddyfile /etc/caddy/
ADD run.sh /root/
CMD sh /root/run.sh
_EOF_

docker build -t registry.${REGION}.bluemix.net/$NS/kube .
while ! bx cr image-list | grep -q "registry.${REGION}.bluemix.net/$NS/kube"
do
    docker push registry.${REGION}.bluemix.net/$NS/kube
done

# 创建面板运行环境
kubectl run kube --image=registry.${REGION}.bluemix.net/$NS/kube --port=80
kubectl expose deployment kube --type=LoadBalancer --name=kube --external-ip $IP

# 构建 SS 容器
cat << _EOF_ >Dockerfile
FROM easypi/shadowsocks-libev
ENV SERVER_PORT 443
ENV METHOD aes-256-cfb
ENV PASSWORD $SPW
_EOF_
docker build -t registry.${REGION}.bluemix.net/$NS/ss .
while ! bx cr image-list | grep -q "registry.${REGION}.bluemix.net/$NS/ss"
do
    docker push registry.${REGION}.bluemix.net/$NS/ss
done

# 创建 BBR 构建文件
cat << _EOF_ > bbr.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    app: bbr 
  name: bbr
spec:
  replicas: 1
  selector:
    matchLabels:
      app: bbr
  template:
    metadata:
      labels:
        app: bbr
      name: bbr
    spec:
      containers:
      - env:
        - name: TARGET_HOST
          value: SS_IP
        - name: TARGET_PORT
          value: "443"
        - name: BIND_PORT
          value: "443"
        image: wuqz/lkl:latest
        name: bbr
        securityContext:
          privileged: true
      restartPolicy: Always
_EOF_

# 创建 SS 运行环境
kubectl run ss --image=registry.${REGION}.bluemix.net/$NS/ss --port=443
if $BBR; then
    kubectl expose deployment ss --name=ss
    sed -i "s/SS_IP/$(kubectl get svc ss -o=custom-columns=IP:.spec.clusterIP | tail -n1)/g" bbr.yaml
    kubectl create -f bbr.yaml
    kubectl expose deployment bbr --type=LoadBalancer --port=443 --name=ss-tcp --external-ip $IP
else
    kubectl expose deployment ss --type=LoadBalancer --name=ss-tcp --external-ip $IP
fi
kubectl expose deployment ss --type=LoadBalancer --name=ss-udp --external-ip $IP --protocol="UDP"

# 删除构建环境
kubectl delete pod build

 

 这两个脚本是一键搭建 SS 脚本中用到的脚本。

意思还不是很理解。

大概是第一个脚本,安装了一个alpine。

第二个脚本又构建一个SS服务器。

不懂,继续研究。

怕脚本下载不到,先存一下。

 






以上是关于解决了好几个软件的构建问题,在解决部署问题,bluemix部署的主要内容,如果未能解决你的问题,请参考以下文章

管理多个项目的元构建解决方案

使用 Git 和 Jenkins 构建持续集成和交付平台

在 VSTS 的单一解决方案中部署多个项目

构建之法阅读笔记

Postman+Newman+Jenkins+Git持续集成时遇到的问题

jenkins集群使用k8s部署,pipeline中文乱码的问题解决记录