溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

物理機(jī)安裝minikube

發(fā)布時間:2020-03-04 15:28:35 來源:網(wǎng)絡(luò) 閱讀:553 作者:zyx1990zm 欄目:系統(tǒng)運(yùn)維

Kubernetes(k8s)是自動化容器操作的開源平臺,基于這個平臺,你可以進(jìn)行容器部署,資源調(diào)度和集群擴(kuò)容等操作。如果你曾經(jīng)用過Docker部署容器,那么可以將Docker看成Kubernetes底層使用的組件,Kubernetes是Docker的上層封裝,通過它可以很方便的進(jìn)行Docker集群的管理。今天我們使用minikube在單機(jī)上進(jìn)行Kubernetes集群的部署,目的是讓我們對k8s有個初步的認(rèn)識。

Minikube 支持以下 Kubernetes 功能

  • DNS

  • NodePorts

  • ConfigMaps 和 Secrets

  • Dashboards

  • 容器運(yùn)行時: Docker、CRI-O?以及?containerd

  • 啟用 CNI (容器網(wǎng)絡(luò)接口)

  • Ingress

  1. 關(guān)閉安全策略

/usr/bin/systemctl?stop?firewalld
/usr/bin/systemctl?disable?firewalld
/usr/sbin/iptables?-F?&&?/usr/sbin/iptables?-X?&&?/usr/sbin/iptables?-F?-t?nat?&&?/usr/sbin/iptables?-X?-t?nat?&&?/usr/sbin/iptables?-P?FORWARD?ACCEPT
/usr/sbin/iptables?-P?FORWARD?ACCEPT
/usr/bin/sed?-i?'s/SELINUX=enforcing/SELINUX=disabled/g'?/etc/selinux/config
setenforce?0


2. 安裝docker

yum?install?-y?epel-release
/usr/bin/yum?install?-y?conntrack?wget?net-tools?jq?yum-utils?ntpdate?ntp?ipvsadm?ipset?device-mapper-persistent-data?iptables?curl?sysstat?libseccomp?wget?lrzsz?bash-completion
yum-config-manager?--add-repo?http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum?install?-y?docker-ce-18.09.4?docker-ce-cli-18.09.4
systemctl?start?docker
systemctl?enable?docker


3.加載所有節(jié)點(diǎn)IPVS模塊

usr/sbin/modprobe?ip_vs
/usr/sbin/modprobe?ip_vs_rr
/usr/sbin/modprobe?ip_vs_wrr
/usr/sbin/modprobe?ip_vs_sh
/usr/sbin/modprobe?nf_conntrack_ipv4


4.關(guān)閉swap緩存

/usr/sbin/swapoff?-a
/usr/bin/sed?-i?'/?swap?/?s/^\(.*\)$/#\1/g'?/etc/fstab


5.優(yōu)化內(nèi)核參數(shù)

cat?>/etc/sysctl.d/k8s.conf?<<EOF
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1
net.ipv4.ip_forward=1
net.ipv4.tcp_tw_recycle=0
vm.swappiness=0?#?禁止使用?swap?空間,只有當(dāng)系統(tǒng)?OOM?時才允許使用它
vm.overcommit_memory=1?#?不檢查物理內(nèi)存是否夠用
vm.panic_on_oom=0?#?開啟?OOM
vm.swappiness=0
fs.inotify.max_user_instances=8192
fs.inotify.max_user_watches=1048576
fs.file-max=52706963
fs.nr_open=52706963
net.ipv6.conf.all.disable_ipv6=1
net.netfilter.nf_conntrack_max=2310720
EOF

modprobe?br_netfilter
sysctl?-p?/etc/sysctl.d/k8s.conf

以上步驟就是minikube的初始化環(huán)境,同時也是kubeadm的初始化環(huán)境,只是運(yùn)行不同的命令而已,minikube內(nèi)部就是運(yùn)行kubeadm。

6.下載軟件

wget?https://storage.googleapis.com/kubernetes-release/release/v1.16.0/bin/linux/amd64/kubectl
chmod?+x?./kubectl
mv?./kubectl?/usr/local/bin/kubectl

curl?-Lo?minikube?https://storage.googleapis.com/minikube/releases/v1.4.0/minikube-linux-amd64?\
??&&?chmod?+x?minikube

國外網(wǎng)站,很慢,最好自己找資源(FQ)下載這兩個文件,我下載的k8是1.16.0版本,想下載最新版或指定版本就更改版本號就行。


7.運(yùn)行minikubu

minikube?start?--image-repository='registry.cn-hangzhou.aliyuncs.com/google_containers'?--vm-driver=none

minikube start?命令可用于啟動集群。 此命令將創(chuàng)建并配置一臺虛擬機(jī),使其運(yùn)行單節(jié)點(diǎn) Kubernetes 集群。指定國內(nèi)鏡像,可省卻國外下載鏡像步驟,去網(wǎng)上翻minikube的文章,會發(fā)現(xiàn)基本上都是各種報錯,我是在一臺裸機(jī)上部署的,除了開發(fā)工具啥都沒裝, 此命令還會配置您的?kubectl?安裝,以便使其能與您的 Kubernetes 集群正確通信。

指定 VM 驅(qū)動程序

您可以通過將?--vm-driver=<enter_driver_name>?參數(shù)添加到?minikube start?來更改 VM 驅(qū)動程序。 例如命令:

minikube?start?--vm-driver=<driver_name>

Minikube 支持以下驅(qū)動程序

注意:?有關(guān)支持的驅(qū)動程序以及如何安裝插件的詳細(xì)信息,請參閱驅(qū)動程序。
  • virtualbox

  • vmwarefusion

  • kvm2 (驅(qū)動安裝)

  • hyperkit (驅(qū)動安裝)

  • hyperv (驅(qū)動安裝) 請注意,下面的 IP 是動態(tài)的,可以更改??梢允褂?minikube ip?檢索。

  • vmware (驅(qū)動安裝) (VMware 統(tǒng)一驅(qū)動)

  • none (在主機(jī)上運(yùn)行Kubernetes組件,而不是在 VM 中。使用該驅(qū)動依賴 Docker (安裝 Docker) 和 Linux 環(huán)境)

成功顯示

*?minikube?1.6.2?is?available!?Download?it:?https://github.com/kubernetes/minikube/releases/tag/v1.6.2
*?To?disable?this?notice,?run:?'minikube?config?set?WantUpdateNotification?false'

!?minikube?v1.4.0?on?Centos?7.7.1908
*?Using?image?repository?registry.cn-hangzhou.aliyuncs.com/google_containers
*?Running?on?localhost?(CPUs=4,?Memory=7521MB,?Disk=51175MB)?...
*?OS?release?is?CentOS?Linux?7?(Core)
*?Preparing?Kubernetes?v1.16.0?on?Docker?18.09.4?...
*?Downloading?kubeadm?v1.16.0
*?Downloading?kubelet?v1.16.0
*?Pulling?images?...
*?Launching?Kubernetes?...?
*?Configuring?local?host?environment?...
*?
!?The?'none'?driver?provides?limited?isolation?and?may?reduce?system?security?and?reliability.
!?For?more?information,?see:
??-?https://minikube.sigs.k8s.io/docs/reference/drivers/none/
*?
!?kubectl?and?minikube?configuration?will?be?stored?in?/root
!?To?use?kubectl?or?minikube?commands?as?your?own?user,?you?may?need?to?relocate?them.?For?example,?to?overwrite?your?own?settings,?run:
*?
??-?sudo?mv?/root/.kube?/root/.minikube?$HOME
??-?sudo?chown?-R?$USER?$HOME/.kube?$HOME/.minikube
*?
*?This?can?also?be?done?automatically?by?setting?the?env?var?CHANGE_MINIKUBE_NONE_USER=true
*?Waiting?for:?apiserver?proxy?etcd?scheduler?controller?dns
*?Done!?kubectl?is?now?configured?to?use?"minikube"

在運(yùn)行Pulling?images的時候另開個終端運(yùn)行:
systemctl?enable?kubelet

在Pulling images的時候很慢,因?yàn)殓R像很多,有的很大,比較慢,可以通過docker images查看已經(jīng)下載完成的鏡像,鏡像組件功能在這里不做介紹。

registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver????????????v1.16.0?????????????b305571ca60a????????4?months?ago????????217MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy????????????????v1.16.0?????????????c21b0c7400f9????????4?months?ago????????86.1MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager???v1.16.0?????????????06a629a7e51c????????4?months?ago????????163MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler????????????v1.16.0?????????????301ddc62b80b????????4?months?ago????????87.3MB
registry.cn-hangzhou.aliyuncs.com/google_containers/etcd??????????????????????3.3.15-0????????????b2756210eeab????????4?months?ago????????247MB
registry.cn-hangzhou.aliyuncs.com/google_containers/coredns???????????????????1.6.2???????????????bf261d157914????????5?months?ago????????44.1MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-addon-manager????????v9.0.2??????????????bd12a212f9dc????????5?months?ago????????83.1MB
registry.cn-hangzhou.aliyuncs.com/google_containers/pause?????????????????????3.1?????????????????da86e6ba6ca1????????2?years?ago?????????742kB
registry.cn-hangzhou.aliyuncs.com/google_containers/storage-provisioner???????v1.8.1??????????????4689081edb10????????2?years?ago?????????80.8MB

8.添加快捷鍵

source?<(kubectl?completion?bash)
echo?"source?<(kubectl?completion?bash)"?>>~/.bashrc

9.測試

kubectl?get?nodes
NAME???????STATUS???ROLES????AGE????VERSION
minikube???Ready????master???2m8s???v1.16.0

kubectl?get?pods?-n?kube-system
NAME???????????????????????????????READY???STATUS????RESTARTS???AGE
coredns-67c766df46-2n8bz???????????1/1?????Running???1??????????43m
coredns-67c766df46-stttx???????????1/1?????Running???1??????????43m
etcd-minikube??????????????????????1/1?????Running???1??????????42m
kube-addon-manager-minikube????????1/1?????Running???1??????????42m
kube-apiserver-minikube????????????1/1?????Running???1??????????42m
kube-controller-manager-minikube???1/1?????Running???1??????????42m
kube-proxy-2v42d???????????????????1/1?????Running???1??????????43m
kube-scheduler-minikube????????????1/1?????Running???1??????????42m
storage-provisioner????????????????1/1?????Running???1??????????42m

10. 刪除集群

minikube?delete
rm?-rf?/root/.minikube




向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI