centos8下k8s安裝記錄

系統(tǒng)配置

  • 關閉交換分區(qū)
sudo sed -i 's/.*swap.*/#&/' /etc/fstab
  • 禁用selinux
sudo sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
  • 關閉防火墻
sudo systemctl stop firewalld.service
sudo systemctl disable firewalld.service
  • 添加K8S源

將如下內容保存到:/etc/yum.repos.d/kubernetes.repo

[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg

由于目前阿里鏡像中還沒有CentOS 8的 Kubernetes钠绍,但是可以使用CentOS 7 的安裝包呛讲,所以上面是使用的kubernetes-el7-x86_64厦滤,如果有CentOS8的榄檬,則為kubernetes-el8-x86_64恨豁。

安裝docker

yum install -y yum-utils device-mapper-persistent-data lvm2 net-tools
  • 安裝kubectl沽瞭、kubelet奠骄、kubeadm
sudo yum install -y kubectl kubelet kubeadm
sudo systemctl enable kubelet
sudo systemctl start kubelet

初始化kubernetes集群

kubeadm init --apiserver-advertise-address=0.0.0.0 --apiserver-cert-extra-sans=127.0.0.1 --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.20.5 --pod-network-cidr=10.10.0.0/16
[init] Using Kubernetes version: v1.20.5
[preflight] Running pre-flight checks
        [WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/
        [WARNING SystemVerification]: this Docker version is not on the list of validated versions: 20.10.5. Latest validated version: 19.03
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'
[certs] Using certificateDir folder "/etc/kubernetes/pki"
[certs] Generating "ca" certificate and key
[certs] Generating "apiserver" certificate and key
[certs] apiserver serving cert is signed for DNS names [kmaster kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 192.168.31.150 127.0.0.1]
[certs] Generating "apiserver-kubelet-client" certificate and key
[certs] Generating "front-proxy-ca" certificate and key
[certs] Generating "front-proxy-client" certificate and key
[certs] Generating "etcd/ca" certificate and key
[certs] Generating "etcd/server" certificate and key
[certs] etcd/server serving cert is signed for DNS names [kmaster localhost] and IPs [192.168.31.150 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [kmaster localhost] and IPs [192.168.31.150 127.0.0.1 ::1]
[certs] Generating "etcd/healthcheck-client" certificate and key
[certs] Generating "apiserver-etcd-client" certificate and key
[certs] Generating "sa" key and public key
[kubeconfig] Using kubeconfig folder "/etc/kubernetes"
[kubeconfig] Writing "admin.conf" kubeconfig file
[kubeconfig] Writing "kubelet.conf" kubeconfig file
[kubeconfig] Writing "controller-manager.conf" kubeconfig file
[kubeconfig] Writing "scheduler.conf" kubeconfig file
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Starting the kubelet
[control-plane] Using manifest folder "/etc/kubernetes/manifests"
[control-plane] Creating static Pod manifest for "kube-apiserver"
[control-plane] Creating static Pod manifest for "kube-controller-manager"
[control-plane] Creating static Pod manifest for "kube-scheduler"
[etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"
[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests". This can take up to 4m0s
[kubelet-check] Initial timeout of 40s passed.
[apiclient] All control plane components are healthy after 65.504071 seconds
[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
[kubelet] Creating a ConfigMap "kubelet-config-1.20" in namespace kube-system with the configuration for the kubelets in the cluster
[upload-certs] Skipping phase. Please see --upload-certs
[mark-control-plane] Marking the node kmaster as control-plane by adding the labels "node-role.kubernetes.io/master=''" and "node-role.kubernetes.io/control-plane='' (deprecated)"
[mark-control-plane] Marking the node kmaster as control-plane by adding the taints [node-role.kubernetes.io/master:NoSchedule]
[bootstrap-token] Using token: biu65a.im9cfd9hpve35ysd
[bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles
[bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to get nodes
[bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials
[bootstrap-token] configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token
[bootstrap-token] configured RBAC rules to allow certificate rotation for all node client certificates in the cluster
[bootstrap-token] Creating the "cluster-info" ConfigMap in the "kube-public" namespace
[kubelet-finalize] Updating "/etc/kubernetes/kubelet.conf" to point to a rotatable kubelet client certificate and key
[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxy

Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

Alternatively, if you are the root user, you can run:

  export KUBECONFIG=/etc/kubernetes/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:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 192.168.31.150:6443 --token biu65a.im9cfd9hpve35ysd \
    --discovery-token-ca-cert-hash sha256:5ae66076d6710c025bb7827fccabd879b1faad35b83b61e61b315084afb249d1 

  • 配置訪問kubectl
  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config
  • 節(jié)點機加入k8s集群
kubeadm join 192.168.31.150:6443 --token o4ohcq.rig9w95z3fzbzean  \
    --discovery-token-ca-cert-hash sha256:caba1868d023c2002c927612bde410817d025d55b51bddad606659605f8e69d4 

安裝calico網(wǎng)絡

這里沒有使用flannel主要是沒有測通pod訪問node ip,時間原因豆同,暫時放棄。

#無法下載時通過本地上傳服務器再執(zhí)行
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml

安裝kubernetes-dashboard

由于我的k8s版本是1.20.5,所以我直接上了2.2.0的dashboard

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.2.0/aio/deploy/recommended.yaml
  • 本地機執(zhí)行代理
    網(wǎng)上有很多暴露端口的方式含鳞,這里在不修改任何文件的情況下快速實現(xiàn)訪問以便進行測試影锈,如有需要可自行查找相關文檔。
?  ~ kubectl proxy
  • 創(chuàng)建token
kubectl create sa dashboard-admin -n kube-system
  • 授權token訪問
kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin
  • 獲取token
ADMIN_SECRET=$(kubectl get secrets -n kube-system | grep dashboard-admin | awk '{print $1}')
DASHBOARD_LOGIN_TOKEN=$(kubectl describe secret -n kube-system ${ADMIN_SECRET} | grep -E '^token' | awk '{print $2}')
echo ${DASHBOARD_LOGIN_TOKEN}
  • 輸入剛獲取的token即可成功

參考

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市熔吗,隨后出現(xiàn)的幾起案子辆床,更是在濱河造成了極大的恐慌,老刑警劉巖桅狠,帶你破解...
    沈念sama閱讀 219,270評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件讼载,死亡現(xiàn)場離奇詭異,居然都是意外死亡中跌,警方通過查閱死者的電腦和手機咨堤,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,489評論 3 395
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來漩符,“玉大人吱型,你說我怎么就攤上這事≡山觯” “怎么了津滞?”我有些...
    開封第一講書人閱讀 165,630評論 0 356
  • 文/不壞的土叔 我叫張陵铝侵,是天一觀的道長。 經(jīng)常有香客問我触徐,道長咪鲜,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,906評論 1 295
  • 正文 為了忘掉前任撞鹉,我火速辦了婚禮疟丙,結果婚禮上,老公的妹妹穿的比我還像新娘鸟雏。我一直安慰自己享郊,他們只是感情好,可當我...
    茶點故事閱讀 67,928評論 6 392
  • 文/花漫 我一把揭開白布孝鹊。 她就那樣靜靜地躺著炊琉,像睡著了一般。 火紅的嫁衣襯著肌膚如雪又活。 梳的紋絲不亂的頭發(fā)上苔咪,一...
    開封第一講書人閱讀 51,718評論 1 305
  • 那天,我揣著相機與錄音柳骄,去河邊找鬼团赏。 笑死,一個胖子當著我的面吹牛耐薯,可吹牛的內容都是我干的舔清。 我是一名探鬼主播,決...
    沈念sama閱讀 40,442評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼曲初,長吁一口氣:“原來是場噩夢啊……” “哼鸠踪!你這毒婦竟也來了?” 一聲冷哼從身側響起复斥,我...
    開封第一講書人閱讀 39,345評論 0 276
  • 序言:老撾萬榮一對情侶失蹤营密,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后目锭,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體评汰,經(jīng)...
    沈念sama閱讀 45,802評論 1 317
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,984評論 3 337
  • 正文 我和宋清朗相戀三年痢虹,在試婚紗的時候發(fā)現(xiàn)自己被綠了被去。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,117評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡奖唯,死狀恐怖惨缆,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤坯墨,帶...
    沈念sama閱讀 35,810評論 5 346
  • 正文 年R本政府宣布寂汇,位于F島的核電站,受9級特大地震影響捣染,放射性物質發(fā)生泄漏骄瓣。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,462評論 3 331
  • 文/蒙蒙 一耍攘、第九天 我趴在偏房一處隱蔽的房頂上張望榕栏。 院中可真熱鬧,春花似錦蕾各、人聲如沸扒磁。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,011評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽妨托。三九已至,卻和暖如春检访,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背仔掸。 一陣腳步聲響...
    開封第一講書人閱讀 33,139評論 1 272
  • 我被黑心中介騙來泰國打工脆贵, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人起暮。 一個月前我還...
    沈念sama閱讀 48,377評論 3 373
  • 正文 我出身青樓卖氨,卻偏偏與公主長得像,于是被迫代替她去往敵國和親负懦。 傳聞我的和親對象是個殘疾皇子筒捺,可洞房花燭夜當晚...
    茶點故事閱讀 45,060評論 2 355

推薦閱讀更多精彩內容