mips64編譯、部署 federation v2 版本應用

近日,筆者自行買了龍芯臺式機並在上面安裝了 kubernetes 1.16 的集羣順帶也弄了聯邦集羣 v2版本的架構,連同依賴、部署測試作完,不得不說 mips 架構如今性能真的不怎麼樣。好了,很少說了就送上 mips 架構上編譯組件過程、及其命令吧node

  • 一、須要編譯的命令golangci-lint,必須的,弄完了把它複製到/usr/sbin下面
[root@master1 ~]# git clone https://github.com/golangci/golangci-lint.git $GOPATH/src/github.com/golangci/golangci-lint
[root@master1 ~]# cd $GOPATH/src/github.com/golangci/golangci-lint
[root@master1 golangci-lint]# go build -ldflags "-X 'main.version=$(git describe --tags)' -X 'main.commit=$(git rev-parse --short HEAD)' -X 'main.date=$(date -u +%Y-%m-%dT%H:%M:%SZ)'" -o golangci-lint cmd/golangci-lint/main.go
[root@master1 golangci-lint]# ./golangci-lint --version
golangci-lint has version v1.17.1-8-gd2b1eea built from d2b1eea on 2019年 08月 30日 星期五 15:30:41 CST
複製代碼
  • 二、kubefed組件hyperfed
[root@master1 ~]# git clone https://github.com/kubernetes-sigs/kubefed.git /root/go/src/sigs.k8s.io/kubefed
[root@master1 ~]# cd /root/go/src/sigs.k8s.io/kubefed
[root@master1 kubefed]# CGO_ENABLED=0 go build -ldflags "-X sigs.k8s.io/kubefed/pkg/version.version=`git describe --always` -X sigs.k8s.io/kubefed/pkg/version.gitCommit=`git rev-parse HEAD` -X sigs.k8s.io/kubefed/pkg/version.gitTreeState=clean -X sigs.k8s.io/kubefed/pkg/version.buildDate=$(date -u +%Y-%m-%dT%H:%M:%SZ) " -o bin/hyperfed-linux-mips64el cmd/hyperfed/main.go 
[root@mfsmaster kubefed]# ./bin/hyperfed-linux-mips64el --help
Combined binary for KubeFed
Usage:
  hyperfed COMMAND [flags]
  hyperfed [command]
Available Commands:
  controller-manager 
  help               Help about any command
  kubefedctl         kubefedctl controls a Kubernetes Cluster Federation
  webhook            Start a kubefed webhook server
Flags:
      --alsologtostderr                  log to standard error as well as files
  -h, --help                             help for hyperfed
      --log-backtrace-at traceLocation   when logging hits line file:N, emit a stack trace (default :0)
      --log-dir string                   If non-empty, write log files in this directory
      --log-file string                  If non-empty, use this log file
      --log-flush-frequency duration     Maximum number of seconds between log flushes (default 5s)
      --logtostderr                      log to standard error instead of files (default true)
      --skip-headers                     If true, avoid header prefixes in the log messages
      --stderrthreshold severity         logs at or above this threshold go to stderr
  -v, --v Level                          number for the log level verbosity
      --vmodule moduleSpec               comma-separated list of pattern=N settings for file-filtered logging
Use "hyperfed [command] --help" for more information about a command.
複製代碼
  • 三、kubefed組件controller-manager
[root@master1 kubefed]# CGO_ENABLED=0 go build -ldflags "-X sigs.k8s.io/kubefed/pkg/version.version=`git describe --always` -X sigs.k8s.io/kubefed/pkg/version.gitCommit=`git rev-parse HEAD` -X sigs.k8s.io/kubefed/pkg/version.gitTreeState=clean -X sigs.k8s.io/kubefed/pkg/version.buildDate=$(date -u +%Y-%m-%dT%H:%M:%SZ)" -o bin/controller-manager-linux-mips64el cmd/controller-manager/main.go
[root@master1 kubefed]# bin/controller-manager-linux-mips64el --version
KubeFed controller-manager version: version.Info{Version:"v0.1.0-rc6-39-ga8e670d29", GitCommit:"a8e670d290fd71be0a5f61e8e64431a8d67996c5", GitTreeState:"clean", BuildDate:"2019-08-29T22:50:54Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/mips64le"}
複製代碼
  • 四、kubefed組件webhook
[root@master1 kubefed]# CGO_ENABLED=0 go build -ldflags "-X sigs.k8s.io/kubefed/pkg/version.version=`git describe --always` -X sigs.k8s.io/kubefed/pkg/version.gitCommit=`gir rev-parse HEAD` -X sigs.k8s.io/kubefed/pkg/version.gitTreeState=clean -X sigs.k8s.io/kubefed/pkg/version.buildDate=$(date -u +%Y-%m-%dT%H:%M:%SZ)" -o bin/webhook-linux-mips64elcmd/webhook/main.go 
[root@mfsmaster kubefed]# ./bin/webhook-linux-mips64el version
KubeFed admission webhook version: version.Info{Version:"v0.1.0-rc6-39-ga8e670d29", GitCommit:"a8e670d290fd71be0a5f61e8e64431a8d67996c5", GitTreeState:"clean", BuildDate:"2019-08-29T22:50:54Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/mips64le"}
複製代碼
  • 五、kubefed組件kubefedctl
[root@master1 kubefed]# CGO_ENABLED=0 go build -ldflags "-X sigs.k8s.io/kubefed/pkg/version.version=`git describe --always` -X sigs.k8s.io/kubefed/pkg/version.gitCommit=`git rev-parse HEAD` -X sigs.k8s.io/kubefed/pkg/version.gitTreeState=clean -X sigs.k8s.io/kubefed/pkg/version.buildDate=$(date -u +%Y-%m-%dT%H:%M:%SZ)" -o bin/kubefedctl-linux-mips64el cmd/kubefedctl/main.go
[root@master1 kubefed]# ./bin/kubefedctl-linux-mips64el version
kubefedctl version: version.Info{Version:"v0.1.0-rc6-39-ga8e670d29", GitCommit:"a8e670d290fd71be0a5f61e8e64431a8d67996c5", GitTreeState:"clean", BuildDate:"2019-08-29T22:50:54Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/mips64le"}
複製代碼
  • 六、kubefed組件e2e
[root@master1 kubefed]# go test -c -ldflags "-X sigs.k8s.io/kubefed/pkg/version.version=`git describe --always` -X sigs.k8s.io/kubefed/pkg/version.gitCommit=`git rev-parse HEAD` -X sigs.k8s.io/kubefed/pkg/version.gitTreeState=clean -X sigs.k8s.io/kubefed/pkg/version.buildDate=$(date -u +%Y-%m-%dT%H:%M:%SZ)" -o bin/e2e-linux-mipsd64el ./test/e2e
複製代碼
  • 七、kubebuilder組件編譯
[root@master1 kubebuilder]# git clone https://github.com/kubernetes-sigs/kubebuilder.git $GOPATH/src/sigs.k8s.io
[root@master1 kubebuilder]# cd $GOPATH/src/sigs.k8s.io/kubebuilder
[root@master1 kubebuilder]# vim cmd/version/version.go
var (
        kubeBuilderVersion      = "v2.0.0-alpha"  //output of $(git describe --always)
        kubernetesVendorVersion = "v1.13.7"  //version of kubernetes
        goos                    = "linux"  //output of $(go env GOOS)
        goarch                  = "mips64le"  //output of $(go env GOARCH)
        gitCommit               = "b46a3c2bde8e471646bf844f1591aa31abef1ab8" // sha1 from git, output of $(git rev-parse HEAD)

        buildDate = "2019-09-06T06:23:24Z" //output of $(date -u +'%Y-%m-%dT%H:%M:%SZ')
)
[root@master1 kubebuilder]# make #或者執行 go build -o bin/kubebuilder ./cmd
go build -o bin/kubebuilder ./cmd
go test -v ./cmd/... ./pkg/...
.............
複製代碼

##正式安裝federation v2版本linux

1.建立兩個k8s集羣git

1.1 kubeadm init 使用命令行參數github

kubeadm init --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.15.1
複製代碼

1.1.1 kubeadm 使用配置文件安裝golang

[root@master1 ~]# cat kubeadm-init-config.yaml
apiVersion: kubeadm.k8s.io/v1beta1
kind: ClusterConfiguration
kubernetesVersion: v1.16.0
clusterName: kubernetes
networking:
 podSubnet: 10.244.0.0/16
 dnsDomain: cluster.local
 serviceSubnet: 10.96.0.0/12
apiServer:
 advertise-address: 192.168.0.77
 external-hostname: master1
 authorization-mode: RBAC
 default-not-ready-toleration-seconds: 20
 default-unreachable-toleration-seconds: 15
 enable-bootstrap-token-auth: true
 anonymous-auth: true
 allow-privileged: true
 audit-webhook-initial-backoff: 60s
 kubelet-timeout: 300s
 request-timeout: 5m
 timeoutForControlPlane: 10m0s
controllerManager:
 node-monitor-grace-period: 6s
 node-monitor-period: 1s
 pod-eviction-timeout: 5s
 feature-gates: "TaintBasedEvictions=false"
 concurrent-deployment-syncs: 3
 concurrent-endpoint-syncs: 3
 leader-elect: "true"
imageRepository: registry.cn-hangzhou.aliyuncs.com/google_containers
dns:
 type: CoreDNS
etcd:
 local:
   dataDir: /var/lib/etcd
---
apiVersion: kubeadm.k8s.io/v1beta1
kind: InitConfiguration
localAPIEndpoint:
 advertiseAddress: 192.168.0.77
 bindPort: 6443
nodeRegistration:
 name: master1
 taints:
   - key: "kubeadmNode"
     value: "master"
     effect: "NoSchedule"
 kubeletExtraArgs:
   cgroup-driver: "cgroupfs"
[root@master1 ~]# kubeadm init --config /etc/kubernetes/kubeadm-config.yaml
複製代碼

2.配置kubeconfigweb

2.1 三個集羣配置docker

[root@master1 ~]# cat .kube/config
apiVersion: v1
clusters:
- cluster:
   certificate-authority-data: LS0tLS1CRUdJTi
   server: https://192.168.0.87:6443
 name: master1
- cluster:
   certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN5R
   server: https://192.168.0.77:6443
 name: master2
- cluster:
   certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN5R
   server: https://192.168.0.67:6443
 name: master3
contexts:
- context:
   cluster: master1
   namespace: default
   user: kubernetes-admin1
 name: master1
- context:
   cluster: master2
   namespace: default
   user: kubernetes-admin2
 name: master2
- context:
   cluster: master3
   namespace: default
   user: kubernetes-admin3
 name: master3
current-context: master1
kind: Config
preferences: {}
users:
- name: kubernetes-admin1
 user:
   client-certificate-data: LS0tLS1JSU
   client-key-data: LS0tLS1CRUdJTiBSU0
   token: eyJhbGciOiJSUzI1NiIsImtpZCI6
- name: kubernetes-admin2
 user:
   client-certificate-data: LS0tLS1CRU
   client-key-data: LS0tLS1CRUdJTiBSU0
   token: eyJhbGciOiJSUzI1NiIsImtpZCI6
- name: kubernetes-master3
 user:
   client-certificate-data: LS0tLS1CRUd
   client-key-data: LS0tLS1CRUdJTiBSU0E
複製代碼

2.2 查看kubeconfig配置bootstrap

[root@master1 ~]# kubectl config get-clusters
NAME
master1
master2
master3
[root@master1 ~]# kubectl config get-contexts
CURRENT   NAME      CLUSTER   AUTHINFO            NAMESPACE
*         master1   master1   kubernetes-admin1   default
         master2   master2   kubernetes-admin2   default
         vm1       vm1       kubernetes-vm1      default
複製代碼

2.3 部署federation控制面板。用上面編譯的hyperfed-linux-mips64le程序構建自定義鏡像vim

[root@master1 ~]# cat >>go/src/sigs.k8s.io/kubefed/images/kubefed/Dockerfile
from huangxg20171010/fedora21-base
RUN useradd -u 1001 hyperfed
RUN mkdir -p /hyperfed
WORKDIR /hyperfed/
COPY hyperfed /hyperfed/hyperfed
RUN ln -s hyperfed controller-manager \
&& ln -s hyperfed kubefedctl \
&& ln -s hyperfed webhook
RUN chown -R hyperfed:hyperfed /hyperfed
USER hyperfed
ENTRYPOINT ["./controller-manager"]
[root@master1 ~]# cd go/src/sigs.k8s.io/kubefed/images/kubefed
[root@master1 kubefed]# cp ../../bin/hyperfed-linux-mips64le >>hyperfed
[root@master1 kubefed]# docker build -t >>qiqisa/hyperfed-mips64el:v0.1.0-rc6 .
複製代碼

2.4 修改 deploy-kubefed.sh 不上傳 docker 倉庫、不構建鏡像api

[root@master1 kubefed]# vim ./scripts/deploy-kubefed.sh
function deploy-with-helm() {
.....
#修改 helm 初始化,添加這個 "-i image:version"參數
helm init -i qiqisa/tiller:v2.14.3 --tiller-image --service-account >>tiller
.....
}
#修改不推送 docker 鏡像倉庫
#DOCKER_PUSH="${DOCKER_PUSH-y}"
#DOCKER_PUSH_CMD="docker push ${IMAGE_NAME}"
#if [[ ! "${DOCKER_PUSH}" ]]; then
# DOCKER_PUSH_CMD=
#fi
#修改不構建鏡像
#if [[ ! "${USE_LATEST}" ]]; then
# cd "$(dirname "$0")/.."
# make container IMAGE_NAME=${IMAGE_NAME}
# cd -
# ${DOCKER_PUSH_CMD}
#fi
#cd "$(dirname "$0")/.."
#make kubefedctl #修改不構建 kubefedctl,由於上面已經構建了
#cd -
[root@master1 kubefed]# ./scripts/deploy-kubefed.sh qiqisa/kubefed-mips64el:v0.1.0-rc6 master1 #這個就能夠在當前機器上部署成功
Server: &version.Version{SemVer:"v2.14.2", >>GitCommit:"a8b13cc5ab6a7dbef0a58f5061bcc7c0c61598e7"
, GitTreeState:"dirty"}
NAME:   kubefed
LAST DEPLOYED: Wed Oct 16 23:09:24 2019
NAMESPACE: kube-federation-system
STATUS: DEPLOYED
RESOURCES:
==> v1/ClusterRole
複製代碼

2.5 查看集羣、加入集羣

[root@master1 Desktop]# kubectl get kubefedclusters.core.kubefed.io --all-namespaces >>#能夠查看到當前集羣中只有一個
NAMESPACE                NAME      READY   AGE
kube-federation-system   master1   True    1h
[root@master1 Desktop]# kubefedctl join master2 --v=2 --host-cluster-context master1 #這個host-cluster-context必定是current-context
[root@master1 Desktop]# kubefedctl join master3 --v=2 --host-cluster-context master1
[root@master1 Desktop]# kubectl get kubefedclusters.core.kubefed.io --all-namespaces
NAMESPACE                NAME      READY   AGE
kube-federation-system   master1   True    2h
kube-federation-system   master2   True    32m
kube-federation-system   master3   True    6s
複製代碼

2.6 部署應用

#參考 sample\example裏面的配置文件
複製代碼
相關文章
相關標籤/搜索