本篇內(nèi)容主要講解“怎么安裝Kubernetes”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“怎么安裝Kubernetes”吧!
成都創(chuàng)新互聯(lián)主營(yíng)龍湖網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,成都App定制開(kāi)發(fā),龍湖h5小程序設(shè)計(jì)搭建,龍湖網(wǎng)站營(yíng)銷(xiāo)推廣歡迎龍湖等地區(qū)企業(yè)咨詢(xún)
安裝過(guò)程基本包括下載軟件,下載鏡像,主機(jī)配置,啟動(dòng) Master 節(jié)點(diǎn),配置網(wǎng)絡(luò),啟動(dòng) Node 節(jié)點(diǎn)。
這個(gè)步驟有翻墻能力的人可以直接按照步驟來(lái),沒(méi)有的話(huà)可以使用我打包好的1.6.2軟件包。
首先在自己的翻墻的主機(jī)配置K8S源。
cat <<EOF > /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64 enabled=1 gpgcheck=1 repo_gpgcheck=1 gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg EOF
配置好后,下載軟件包
yum install -y -downloadonly kubelet kubeadm kubectl kubernetes-cni
將下載好的所有 RPM 打包,發(fā)回到本地。這樣就完成了K8S軟件包的下載了。
下載好的 RPM:
https://pan.baidu.com/s/1clIpjC cp6h
下載鏡像可以直接使用我提供的腳本,前提是要能翻墻,你懂的。我自己也已經(jīng)下載過(guò)一份了。提供給大家使用。
#!/usr/bin/env bash images=( kube-proxy-amd64:v1.6.2 kube-controller-manager-amd64:v1.6.2 kube-apiserver-amd64:v1.6.2 kube-scheduler-amd64:v1.6.2 kubernetes-dashboard-amd64:v1.6.0 k8s-DNS-sidecar-amd64:1.14.1 k8s-dns-kube-dns-amd64:1.14.1 k8s-dns-dnsmasq-nanny-amd64:1.14.1 etcd-amd64:3.0.17 pause-amd64:3.0 ) for imageName in ${images[@]} ; do docker pull gcr.io/google_containers/$imageName docker tag gcr.io/google_containers/$imageName registry.cn-beijing.aliyuncs.com/bbt_k8s/$imageName docker push registry.cn-beijing.aliyuncs.com/bbt_k8s/$imageName done quay.io/coreos/flannel:v0.7.0-amd64 docker tag quay.io/coreos/flannel:v0.7.0-amd64 registry.cn-beijing.aliyuncs.com/bbt_k8s/flannel:v0.7.0-amd64 docker push registry.cn-beijing.aliyuncs.com/bbt_k8s/flannel:v0.7.0-amd64
關(guān)于這個(gè)腳本我解釋一下。這個(gè)腳本是下載常用的鏡像,然后回傳到國(guó)內(nèi)的源上,可以將registry.cn-beijing.aliyuncs.com/bbt_k8s改成你自己的地址,必須先用docker login 進(jìn)行登錄,否則可能會(huì)出現(xiàn)權(quán)限認(rèn)證錯(cuò)誤。推薦使用阿里云,網(wǎng)易的服務(wù)。如果使用自己的地址,請(qǐng)注意下面的配置,根據(jù)自己的情況進(jìn)行修改,不在累贅了。
鏡像版本號(hào)說(shuō)明:
軟件 | 版本 | 說(shuō)明 | 備注 |
---|---|---|---|
kube-proxy-amd64 kube-controller-manager-amd64 kube-apiserver-amd64 kube-scheduler-amd64 | v1.6.2 | 這幾個(gè)鏡像一般跟著 K8S 的版本走,例如我安裝的是 K8S 的1.6.2,那么版本號(hào)就是 v1.6.2 | |
kubernetes-dashboard-amd64 | v1.6.0 | 這個(gè)是 K8S 的控制臺(tái)(雖然并不好用,單但是最起碼很適合新手),一般跟著 K8S 的大版本好走,例如我安裝 K8S 的1.6.2,大版本是1.6,所以版本號(hào)是 v1.6.0 | |
k8s-dns-sidecar-amd64 k8s-dns-kube-dns-amd64 k8s-dns-dnsmasq-nanny-amd64 | 1.14.1 | 這個(gè)是 DNS 服務(wù),一般不跟隨 K8S 進(jìn)行升級(jí),具體版本可以參考https://kubernetes.io/docs/getting-started-guides/kubeadm/ | |
etcd-amd64 | 3.0.17 | 這個(gè)是 etcd 服務(wù),一般不跟隨 K8S 進(jìn)行升級(jí),具體版本可以參考https://kubernetes.io/docs/getting-started-guides/kubeadm/ | |
pause-amd64 | 3.0 | 一般不跟隨 K8S 進(jìn)行升級(jí),具體版本可以參考https://kubernetes.io/docs/getting-started-guides/kubeadm/ | 已經(jīng)很長(zhǎng)時(shí)間版本都是3.0了。 |
flannel | v0.7.0-amd64 | 網(wǎng)絡(luò)組件,我這里使用的flannel,當(dāng)然也可以使用其它的。具體版本信息參考對(duì)應(yīng)的網(wǎng)絡(luò)組件,例如flannel是https://github.com/coreos/flannel/tree/master/Documentation |
OK,這些鏡像下載完成就 OK 了,沒(méi)有翻墻工具的,就直接跳過(guò)吧。
上面的內(nèi)容下載好后,我們就可以安裝了。
沒(méi)什么可以介紹的。
yum update -y
K8S 的1.6.x 版本僅僅在 Docker 1.12上測(cè)試過(guò),雖然最新版本 Docker 也可以運(yùn)行,但是不推薦安裝最新版本,免得遇到什么問(wèn)題。
curl -sSL http://acs-public-mirror.oss-cn-hangzhou.aliyuncs.com/docker-engine/internet | sh /dev/stdin 1.12.6
安裝完成后,禁用 Docker 的更新,禁用方式為,在/etc/yum.conf添加
exclude=docker-engine*
主要是配置一些加速器,避免自己下載鏡像速度太慢。
修改/etc/docker/daemon.json 添加如下內(nèi)容:
{ "registry-mirrors": ["https://自己的加速地址"] }
之后就是啟動(dòng)Docker 的服務(wù),
systemctl daemon-reload systemctl enable docker systemctl start docker
主要是開(kāi)啟橋接相關(guān)支持,這個(gè)是 flannel 需要的配置,具體是否需要,看自己的網(wǎng)絡(luò)組件選擇的是什么。
修改/usr/lib/sysctl.d/00-system.conf,將net.bridge.bridge-nf-call-iptables改成1.之后修改當(dāng)前內(nèi)核狀態(tài)
echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables
上傳RPM 包,到自己的服務(wù)器上,然后執(zhí)行
yum install -y *.rpm
之后開(kāi)啟kubelet的開(kāi)機(jī)啟動(dòng)
systemctl enable kubelet
然后配置 kubelet,修改/etc/systemd/system/kubelet.service.d/10-kubeadm.conf成如下文件
[Service] Environment="KUBELET_KUBECONFIG_ARGS=--kubeconfig=/etc/kubernetes/kubelet.conf --require-kubeconfig=true" Environment="KUBELET_SYSTEM_PODS_ARGS=--pod-manifest-path=/etc/kubernetes/manifests --allow-privileged=true" Environment="KUBELET_NETWORK_ARGS=--network-plugin=cni --cni-conf-dir=/etc/cni/net.d --cni-bin-dir=/opt/cni/bin" Environment="KUBELET_DNS_ARGS=--cluster-dns=10.96.0.10 --cluster-domain=cluster.local" Environment="KUBELET_AUTHZ_ARGS=--authorization-mode=Webhook --client-ca-file=/etc/kubernetes/pki/ca.crt" Environment="KUBELET_ALIYUN_ARGS=--pod-infra-container-image=registry-vpc.cn-beijing.aliyuncs.com/bbt_k8s/pause-amd64:3.0" ExecStart= ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_SYSTEM_PODS_ARGS $KUBELET_NETWORK_ARGS $KUBELET_DNS_ARGS $KUBELET_AUTHZ_ARGS $KUBELET_EXTRA_ARGS $KUBELET_ALIYUN_ARGS
在這里主要修正2個(gè)問(wèn)題,一個(gè)是將 POD 的基礎(chǔ)容器修改為我們自己源里面的,另外一個(gè)是最新版本的 K8S 的資源管理和 Docker 默認(rèn)的資源管理方式有沖突,這里把這塊給刪除了。具體可以參考https://github.com/kubernetes/release/issues/306
然后重新 reload 服務(wù)。
systemctl daemon-reload
這樣就完成了主機(jī)環(huán)境的初始化,如果是使用虛擬機(jī),拷貝3份就可以了。如果是實(shí)體機(jī),3臺(tái)都按照這個(gè)步驟來(lái)一遍就好了。然后為每一臺(tái)主機(jī)根據(jù)類(lèi)型設(shè)置好 HostName,K8S會(huì)把 HostName 當(dāng)做主機(jī)標(biāo)識(shí)。
配置完主機(jī)后,我們就可以啟動(dòng)我們的 Master 節(jié)點(diǎn)了,通常 Master 節(jié)點(diǎn)推薦2-3個(gè),本地測(cè)試我們就簡(jiǎn)單一些,一個(gè)節(jié)點(diǎn)就可以了。
export KUBE_REPO_PREFIX="registry-vpc.cn-beijing.aliyuncs.com/bbt_k8s" export KUBE_ETCD_IMAGE="registry-vpc.cn-beijing.aliyuncs.com/bbt_k8s/etcd-amd64:3.0.17" kubeadm init --kubernetes-version=v1.6.2 --pod-network-cidr=10.96.0.0/12
前面2個(gè)環(huán)境變量配置,是讓 kubeadm 初始化的時(shí)候,使用我們的鏡像源下載鏡像。
最后 kubeadm init 是初始化 Master 節(jié)點(diǎn)。其中需要配置的參數(shù)我說(shuō)明一下。
參數(shù) | 意義 | 備注 |
---|---|---|
--kubernetes-version | K8S 的版本號(hào),根據(jù)自己下載的鏡像和 RPM 版本選擇。 | 我這里使用的1.6.2,所以版本為v1.6.2. |
--pod-network-cidr | POD 的網(wǎng)絡(luò),只要不和主機(jī)網(wǎng)絡(luò)沖突就可以,我這里使用的是10.96.0.0/12 | 這個(gè)和上面/etc/systemd/system/kubelet.service.d/10-kubeadm.conf里面聲明的KUBELET_DNS_ARGS掛鉤,請(qǐng)一同修改。 |
執(zhí)行完畢后,稍等一陣,就完成了。
kubeadm init --kubernetes-version=v1.6.2 --pod-network-cidr=10.96.0.0/12 [kubeadm] WARNING: kubeadm is in beta, please do not use it for production clusters. [init] Using Kubernetes version: v1.6.2 [init] Using Authorization mode: RBAC [preflight] Running pre-flight checks [preflight] Starting the kubelet service [certificates] Generated CA certificate and key. [certificates] Generated API server certificate and key. [certificates] API Server serving cert is signed for DNS names [node0 kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 192.168.61.41] [certificates] Generated API server kubelet client certificate and key. [certificates] Generated service account token signing key and public key. [certificates] Generated front-proxy CA certificate and key. [certificates] Generated front-proxy client certificate and key. [certificates] Valid certificates and keys now exist in "/etc/kubernetes/pki" [kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/admin.conf" [kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/kubelet.conf" [kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/controller-manager.conf" [kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/scheduler.conf" [apiclient] Created API client, waiting for the control plane to become ready [apiclient] All control plane components are healthy after 14.583864 seconds [apiclient] Waiting for at least one node to register [apiclient] First node has registered after 6.008990 seconds [token] Using token: e7986d.e440de5882342711 [apiconfig] Created RBAC rules [addons] Created essential addon: kube-proxy [addons] Created essential addon: kube-dns Your Kubernetes master has initialized successfully! To start using your cluster, you need to run (as a regular user): sudo cp /etc/kubernetes/admin.conf $HOME/ sudo chown $(id -u):$(id -g) $HOME/admin.conf export KUBECONFIG=$HOME/admin.conf You should now deploy a pod network to the cluster. Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at: http://kubernetes.io/docs/admin/addons/ You can now join any number of machines by running the following on each node as root: kubeadm join --token 1111.1111111111111 *.*.*.*:6443
安裝完成后,有一個(gè)內(nèi)容非常重要,查看安裝日志,拷貝類(lèi)似于下面的語(yǔ)句,這條語(yǔ)句用來(lái)初始化之后的節(jié)點(diǎn)。
kubeadm join --token 11111.11111111111111 *.*.*.*:6443
接下來(lái)我們就可以去看看我們 K8S 的狀態(tài)。我這使用的是 Mac。 Linux 和 Windows 的同學(xué)自行處理。
安裝 kubectl
brew install kubectl
然后拷貝 Master 節(jié)點(diǎn)上的/etc/kubernetes/admin.conf文件到本機(jī)的~/.kube/config
之后執(zhí)行kebectl get node。我這里已經(jīng)安裝完畢了,所以有全部信息,只要能看到節(jié)點(diǎn),就算是成功了。
接下來(lái)我們安裝網(wǎng)絡(luò)組件,我這里使用的是flannel。創(chuàng)建2個(gè)文件
kube-flannel-rbac.yml
# Create the clusterrole and clusterrolebinding: # $ kubectl create -f kube-flannel-rbac.yml # Create the pod using the same namespace used by the flannel serviceaccount: # $ kubectl create --namespace kube-system -f kube-flannel.yml --- kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: name: flannel rules: - apiGroups: - "" resources: - pods verbs: - get - apiGroups: - "" resources: - nodes verbs: - list - watch - apiGroups: - "" resources: - nodes/status verbs: - patch --- kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: name: flannel roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: flannel subjects: - kind: ServiceAccount name: flannel namespace: kube-system
kube-flannel-ds.yaml
--- apiVersion: v1 kind: ServiceAccount metadata: name: flannel namespace: kube-system --- kind: ConfigMap apiVersion: v1 metadata: name: kube-flannel-cfg namespace: kube-system labels: tier: node app: flannel data: cni-conf.json: | { "name": "cbr0", "type": "flannel", "delegate": { "isDefaultGateway": true } } net-conf.json: | { "Network": "10.96.0.0/12", "Backend": { "Type": "vxlan" } } --- apiVersion: extensions/v1beta1 kind: DaemonSet metadata: name: kube-flannel-ds namespace: kube-system labels: tier: node app: flannel spec: template: metadata: labels: tier: node app: flannel spec: hostNetwork: true nodeSelector: beta.kubernetes.io/arch: amd64 tolerations: - key: node-role.kubernetes.io/master operator: Exists effect: NoSchedule serviceAccountName: flannel containers: - name: kube-flannel image: registry.cn-beijing.aliyuncs.com/bbt_k8s/flannel:v0.7.0-amd64 command: [ "/opt/bin/flanneld", "--ip-masq", "--kube-subnet-mgr" ] securityContext: privileged: true env: - name: POD_NAME valueFrom: fieldRef: fieldPath: metadata.name - name: POD_NAMESPACE valueFrom: fieldRef: fieldPath: metadata.namespace volumeMounts: - name: run mountPath: /run - name: flannel-cfg mountPath: /etc/kube-flannel/ - name: install-cni image: registry.cn-beijing.aliyuncs.com/bbt_k8s/flannel:v0.7.0-amd64 command: [ "/bin/sh", "-c", "set -e -x; cp -f /etc/kube-flannel/cni-conf.json /etc/cni/net.d/10-flannel.conf; while true; do sleep 3600; done" ] volumeMounts: - name: cni mountPath: /etc/cni/net.d - name: flannel-cfg mountPath: /etc/kube-flannel/ volumes: - name: run hostPath: path: /run - name: cni hostPath: path: /etc/cni/net.d - name: flannel-cfg configMap: name: kube-flannel-cfg
然后使用使用命令進(jìn)行配置。
kubectl create -f kube-flannel-rbac.yml kubectl create -f kube-flannel-ds.yaml
分別在2個(gè)Node 節(jié)點(diǎn),執(zhí)行下面的命令。
export KUBE_REPO_PREFIX="registry-vpc.cn-beijing.aliyuncs.com/bbt_k8s" export KUBE_ETCD_IMAGE="registry-vpc.cn-beijing.aliyuncs.com/bbt_k8s/etcd-amd64:3.0.17" kubeadm join --token 1111.111111111111 *.*.*.*:6443
其中 kubeadm join 請(qǐng)參考啟動(dòng) Master 節(jié)點(diǎn)中的內(nèi)容。
理論上我們安裝到這里,K8S 就已經(jīng)可以使用了。接下來(lái)主要是K8S的 Dashboard 的安裝,僅供參考,不一定要安裝。
創(chuàng)建文件kubernetes-dashboard.yaml
# Copyright 2015 Google Inc. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Configuration to deploy release version of the Dashboard UI compatible with # Kubernetes 1.6 (RBAC enabled). # # Example usage: kubectl create -f <this_file> apiVersion: v1 kind: ServiceAccount metadata: labels: app: kubernetes-dashboard name: kubernetes-dashboard namespace: kube-system --- apiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRoleBinding metadata: name: kubernetes-dashboard labels: app: kubernetes-dashboard roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - kind: ServiceAccount name: kubernetes-dashboard namespace: kube-system --- kind: Deployment apiVersion: extensions/v1beta1 metadata: labels: app: kubernetes-dashboard name: kubernetes-dashboard namespace: kube-system spec: replicas: 1 revisionHistoryLimit: 10 selector: matchLabels: app: kubernetes-dashboard template: metadata: labels: app: kubernetes-dashboard spec: containers: - name: kubernetes-dashboard image: registry.cn-beijing.aliyuncs.com/bbt_k8s/kubernetes-dashboard-amd64:v1.6.0 imagePullPolicy: Always ports: - containerPort: 9090 protocol: TCP args: # Uncomment the following line to manually specify Kubernetes API server Host # If not specified, Dashboard will attempt to auto discover the API server and connect # to it. Uncomment only if the default does not work. # - --apiserver-host=http://my-address:port livenessProbe: httpGet: path: / port: 9090 initialDelaySeconds: 30 timeoutSeconds: 30 serviceAccountName: kubernetes-dashboard # Comment the following tolerations if Dashboard must not be deployed on master tolerations: - key: node-role.kubernetes.io/master effect: NoSchedule --- kind: Service apiVersion: v1 metadata: labels: app: kubernetes-dashboard name: kubernetes-dashboard namespace: kube-system spec: type: NodePort ports: - port: 80 targetPort: 9090 selector: app: kubernetes-dashboard
創(chuàng)建文件dashboard-rbac.yaml
kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: name: dashboard-admin roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - kind: ServiceAccount name: default namespace: kube-system
之后執(zhí)行
kubectl create -f dashboard-rbac.yml kubectl create -f kubernetes-dashboard.yaml
之后用下面的命令,獲取到對(duì)應(yīng)端口號(hào)。主要是看 NodePort: <unset> 31867/TCP這樣的內(nèi)容。然后使用http://NodeIp:NodePort訪問(wèn)就可以了,其中 NodeIp 為 Master 或者 Node 的 IP,NodePort為NodePort的端口。
kubectl describe --namespace kube-system service kubernetes-dashboard
到此,這份安裝教程就到這里結(jié)束了。最后奉上一份安裝后的截圖。
到此,相信大家對(duì)“怎么安裝Kubernetes”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢(xún),關(guān)注我們,繼續(xù)學(xué)習(xí)!
文章標(biāo)題:怎么安裝Kubernetes
本文路徑:http://muchs.cn/article20/gddsco.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、網(wǎng)站策劃、品牌網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)、自適應(yīng)網(wǎng)站、外貿(mào)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)