您好,登錄后才能下訂單哦!
Kubernetes(k8s)是自動化容器操作的開源平臺,基于這個平臺,你可以進行容器部署,資源調度和集群擴容等操作。如果你曾經用過Docker部署容器,那么可以將Docker看成Kubernetes底層使用的組件,Kubernetes是Docker的上層封裝,通過它可以很方便的進行Docker集群的管理。今天我們使用minikube在單機上進行Kubernetes集群的部署,目的是讓我們對k8s有個初步的認識。
Minikube 支持以下 Kubernetes 功能:
NodePorts
ConfigMaps 和 Secrets
Dashboards
容器運行時: Docker、CRI-O?以及?containerd
啟用 CNI (容器網絡接口)
Ingress
關閉安全策略
/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.加載所有節點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.關閉swap緩存
/usr/sbin/swapoff?-a /usr/bin/sed?-i?'/?swap?/?s/^\(.*\)$/#\1/g'?/etc/fstab
5.優化內核參數
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?空間,只有當系統?OOM?時才允許使用它 vm.overcommit_memory=1?#?不檢查物理內存是否夠用 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的初始化環境,同時也是kubeadm的初始化環境,只是運行不同的命令而已,minikube內部就是運行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
國外網站,很慢,最好自己找資源(FQ)下載這兩個文件,我下載的k8是1.16.0版本,想下載最新版或指定版本就更改版本號就行。
7.運行minikubu
minikube?start?--image-repository='registry.cn-hangzhou.aliyuncs.com/google_containers'?--vm-driver=none
minikube start
?命令可用于啟動集群。
此命令將創建并配置一臺虛擬機,使其運行單節點 Kubernetes
集群。指定國內鏡像,可省卻國外下載鏡像步驟,去網上翻minikube的文章,會發現基本上都是各種報錯,我是在一臺裸機上部署的,除了開發工具啥都沒裝,
此命令還會配置您的?kubectl?安裝,以便使其能與您的 Kubernetes 集群正確通信。
您可以通過將?--vm-driver=<enter_driver_name>
?參數添加到?minikube start
?來更改 VM 驅動程序。 例如命令:
minikube?start?--vm-driver=<driver_name>
Minikube 支持以下驅動程序:
注意:?有關支持的驅動程序以及如何安裝插件的詳細信息,請參閱驅動程序。
virtualbox
vmwarefusion
kvm2 (驅動安裝)
hyperkit (驅動安裝)
hyperv (驅動安裝) 請注意,下面的 IP 是動態的,可以更改。可以使用?minikube ip
?檢索。
vmware (驅動安裝) (VMware 統一驅動)
none (在主機上運行Kubernetes組件,而不是在 VM 中。使用該驅動依賴 Docker (安裝 Docker) 和 Linux 環境)
成功顯示
*?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" 在運行Pulling?images的時候另開個終端運行: systemctl?enable?kubelet
在Pulling images的時候很慢,因為鏡像很多,有的很大,比較慢,可以通過docker images查看已經下載完成的鏡像,鏡像組件功能在這里不做介紹。
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
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。