Kubernetes 是當前煊赫一時的技術,它已然成爲可開源界的PASS管理平臺的標準,當下文章對大多數是對X86平臺搭建Kubernetes平臺,下面筆者進行在LinuxONE上搭建開源的Kubernetes平臺。
搭建K8S 平臺主流的有兩種方法,node
1. 環境
安裝的環境可使用虛擬機也可使用Lpar,我這是使用的Openstack環境下面的虛擬機。虛擬機的規格爲4C10G50Glinux
系統版本 | IP地址 | 主機名 | K8s version |
---|---|---|---|
Red Hat Enterprise Linux Server release 7.4 | 172.16.35.141 | rhel7-master | 1.17.4 |
Red Hat Enterprise Linux Server release 7.4 | 172.16.35.138 | rhel7-node-1 | 1.17.4 |
環境準備工做git
setenforce 0 sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config swapoff -a && sysctl -w vm.swappiness=0 && sysctl -w net.ipv4.ip_forward=1 cat <<EOF > /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF sysctl --system [root@rhel7-master ~]# yum install rng-tools -y [root@rhel7-master ~]# systemctl enable rngd;systemctl start rngd
二、安裝docker包github
[root@rhel7-master tmp]# wget ftp://ftp.unicamp.br/pub/linuxpatch/s390x/redhat/rhel7.3/docker-17.05.0-ce-rhel7.3-20170523.tar.gz [root@rhel7-master tmp]# tar -xvf docker-17.05.0-ce-rhel7.3-20170523.tar.gz [root@rhel7-master tmp]#cd docker-17.05.0-ce-rhel7.3-20170523 [root@rhel7-master tmp]# cp docker* /usr/local/bin [root@rhel7-master docker-1.11.2-rhel7.2-20160623]# cat > /etc/systemd/system/docker.service << EOF [Unit] Description=docker [Service] User=root #ExecStart=/usr/bin/docker daemon -s overlay ExecStart=/usr/local/bin/dockerd EnvironmentFile=-/etc/sysconfig/docker [Install] WantedBy=multi-user.target EOF [root@rhel7-master docker-1.11.2-rhel7.2-20160623]# cat > /etc/sysconfig/docker <<EOF OPTIONS="daemon -s overlay" EOF [root@rhel7-master docker-1.11.2-rhel7.2-20160623]# 啓動服務 systemctl daemon-reload systemctl restart docker [root@rhel7-master tmp]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [root@rhel7-master tmp]#
三、安裝kubelet、kubeadm 等包
添加yum 源(master 和node 節點都要執行)docker
[root@rhel7-master ~]# cat > /etc/yum.repos.d/os.repo <<EOF [k8s] name=k8s baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-s390x/ gpgcheck=0 enabled=1 [clefos1] name=cle1 baseurl=http://download.sinenomine.net/clefos/7.6/ gpgcheck=0 enabled=1 EOF [root@rhel7-master ~]#
查看 當前repo提供的包的版本bootstrap
yum list kubelet kubeadm kubectl --showduplicates|sort -r
下面進行安裝1.174版本的包api
[root@rhel-master ~]# yum install kubeadm-1.17.4 kubelet-1.17.4 kubectl-1.17.4 -y [root@rhel7-master ~]# systemctl enable --now kubelet
四、利用kubeadm 初始化環境
再此以前須要自行作好下面準備網絡
初始化環境(master 和node 節點都要執行):
一、基於主機名通信
二、時間同步
三、防火牆關閉
四、swapoff -a && sysctl -w vm.swappiness=0 && sysctl -w net.ipv4.ip_forward=1 \
echo 1 > /proc/sys/net/bridge/bridge-nf-call-ip6tables \
echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptablesapp
查看kubeadm 須要哪些基礎的docker imagetcp
[root@rhel7-master ~]# kubeadm config images list k8s.gcr.io/kube-apiserver:v1.17.4 k8s.gcr.io/kube-controller-manager:v1.17.4 k8s.gcr.io/kube-scheduler:v1.17.4 k8s.gcr.io/kube-proxy:v1.17.4 k8s.gcr.io/pause:3.1 k8s.gcr.io/etcd:3.4.3-0 k8s.gcr.io/coredns:1.6.5
能夠看到咱們已經羅列出了須要的docker image ,因爲不可描述的因素,咱們沒法直接訪問k8s.gcr.io
因此須要咱們自行下載這幾個鏡像,我已經把鏡像上傳到了個人docker hub, 你們能夠本身pull
docker pull erickshi/kube-apiserver-s390x:v1.17.4 docker pull erickshi/kube-scheduler-s390x:v1.17.4 docker pull erickshi/kube-controller-manager-s390x:v1.17.4 docker pull erickshi/pause-s390x:3.1 docker pull erickshi/coredns:s390x-1.6.5 docker pull erickshi/etcd:3.4.3-0 docker pull erickshi/pause:3.1
下載完後,咱們須要進行更改爲和咱們列出來同樣的名字,由於kubeadm 會去下載
docker tag erickshi/kube-apiserver-s390x:v1.17.4 k8s.gcr.io/kube-apiserver:v1.17.4 docker tag erickshi/kube-scheduler-s390x:v1.17.4 k8s.gcr.io/kube-scheduler:v1.17.4 docker tag erickshi/kube-controller-manager-s390x:v1.17.4 k8s.gcr.io/kube-controller-manager:v1.17.4 docker tag erickshi/pause-s390x:3.1 k8s.gcr.io/pause:3.1 docker tag erickshi/etcd-s390x:3.4.3-0 k8s.gcr.io/etcd:3.4.3-0 docker tags erickshi/coredns:s390x-1.6.5 k8s.gcr.io/coredns:1.6.5 docker tag erickshi/coredns:s390x-1.6.5 k8s.gcr.io/coredns:1.6.5
除此以外,咱們還須要flannal的鏡像
docker pull erickshi/flannel:v0.12.0-s390x docker tag erickshi/flannel:v0.12.0-s390x k8s.gcr.io/flannel:v0.12.0-s390x
或者在百度雲盤下載,直接導入docker load 便可
連接:https://pan.baidu.com/s/1E5YLM8LhPvdo1mlSsNPVdg 密碼:vfis
進行環境的初始化
[root@rhel-master ~]# kubeadm init --pod-network-cidr=10.244.0.0/16 --kubernetes-[root@rhel-master ~]# kubeadm init --pod-network-cidr=10.244.0.0/16 W0327 02:32:15.413161 6817 version.go:101] could not fetch a Kubernetes version from the internet: unable to get URL "https://dl.k8s.io/release/stable-1.txt": Get https://dl.k8s.io/release/stable-1.txt: dial tcp: lookup dl.k8s.io on [::1]:53: read udp [::1]:32972->[::1]:53: read: connection refused W0327 02:32:15.414720 6817 version.go:102] falling back to the local client version: v1.17.4 W0327 02:32:15.414805 6817 validation.go:28] Cannot validate kube-proxy config - no validator is available W0327 02:32:15.414811 6817 validation.go:28] Cannot validate kubelet config - no validator is available [init] Using Kubernetes version: v1.17.4 [preflight] Running pre-flight checks [WARNING Firewalld]: firewalld is active, please ensure ports [6443 10250] are open or your cluster may not function correctly [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: 17.05.0-ce. Latest validated version: 19.03 [WARNING Hostname]: hostname "rhel-master.novalocal" could not be reached [WARNING Hostname]: hostname "rhel-master.novalocal": lookup rhel-master.novalocal on [::1]:53: read udp [::1]:33466->[::1]:53: read: connection refused [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' [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 [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 [rhel-master.novalocal kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 172.16.35.141] [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 [rhel-master.novalocal localhost] and IPs [172.16.35.141 127.0.0.1 ::1] [certs] Generating "etcd/peer" certificate and key [certs] etcd/peer serving cert is signed for DNS names [rhel-master.novalocal localhost] and IPs [172.16.35.141 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 [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" W0327 02:32:22.545271 6817 manifests.go:214] the default kube-apiserver authorization-mode is "Node,RBAC"; using "Node,RBAC" [control-plane] Creating static Pod manifest for "kube-scheduler" W0327 02:32:22.546219 6817 manifests.go:214] the default kube-apiserver authorization-mode is "Node,RBAC"; using "Node,RBAC" [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 [apiclient] All control plane components are healthy after 12.501743 seconds [upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace [kubelet] Creating a ConfigMap "kubelet-config-1.17" 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 rhel-master.novalocal as control-plane by adding the label "node-role.kubernetes.io/master=''" [mark-control-plane] Marking the node rhel-master.novalocal as control-plane by adding the taints [node-role.kubernetes.io/master:NoSchedule] [bootstrap-token] Using token: ckun8n.l8adw68yhpcsdmdu [bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles [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 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 172.16.35.141:6443 --token ckun8n.l8adw68yhpcsdmdu \ --discovery-token-ca-cert-hash sha256:ea5a0282fa2582d6b10d4ea29a9b76318d1f023109248172e0820531ac1bef5e [root@rhel-master ~]#
拷貝認證文件,而且查看當前pod和節點
[root@rhel-master ~]# kubectl get node,pod --all-namespaces NAME STATUS ROLES AGE VERSION node/rhel-master.novalocal NotReady master 2m59s v1.17.4 NAMESPACE NAME READY STATUS RESTARTS AGE kube-system pod/coredns-6955765f44-cbzss 0/1 Pending 0 2m41s kube-system pod/coredns-6955765f44-dxjfb 0/1 Pending 0 2m41s kube-system pod/etcd-rhel-master.novalocal 1/1 Running 0 2m56s kube-system pod/kube-apiserver-rhel-master.novalocal 1/1 Running 0 2m56s kube-system pod/kube-controller-manager-rhel-master.novalocal 1/1 Running 0 2m56s kube-system pod/kube-proxy-6nmhq 1/1 Running 0 2m41s kube-system pod/kube-scheduler-rhel-master.novalocal 1/1 Running 0 2m56s [root@rhel-master ~]#
安裝flannel
[root@rhel-master ~]# kubectl apply -f https://github.com/coreos/flannel/blob/master/Documentation/kube-flannel.yml
再次查看網絡和節點
[root@rhel-master ~]# kubectl get node,pod --all-namespaces NAME STATUS ROLES AGE VERSION node/rhel-master.novalocal Ready master 9m21s v1.17.4 NAMESPACE NAME READY STATUS RESTARTS AGE kube-system pod/coredns-6955765f44-cbzss 1/1 Running 0 9m3s kube-system pod/coredns-6955765f44-dxjfb 1/1 Running 0 9m3s kube-system pod/etcd-rhel-master.novalocal 1/1 Running 0 9m18s kube-system pod/kube-apiserver-rhel-master.novalocal 1/1 Running 0 9m18s kube-system pod/kube-controller-manager-rhel-master.novalocal 1/1 Running 0 9m18s kube-system pod/kube-flannel-ds-s390x-zv6xl 1/1 Running 0 5m54s kube-system pod/kube-proxy-6nmhq 1/1 Running 0 9m3s kube-system pod/kube-scheduler-rhel-master.novalocal 1/1 Running 0 9m18s [root@rhel-master ~]#
能夠看到節點已經成爲ready 狀態,而且kube-system 的pod 已經所有就緒。目前master節點的安裝搞一個段落,下面安裝node節點
安裝node節點
前置條件:
見環境準備工做
下面直接 加入master節點
kubeadm join 172.16.35.141:6443 --token ckun8n.l8adw68yhpcsdmdu \ --discovery-token-ca-cert-hash sha256:ea5a0282fa2582d6b10d4ea29a9b76318d1f023109248172e0820531ac1bef5e W0330 03:22:57.551161 2546 join.go:346] [preflight] WARNING: JoinControlPane.controlPlane settings will be ignored when control-plane flag is not set. [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: 17.05.0-ce. Latest validated version: 19.03 [WARNING Hostname]: hostname "rhel-node-1.novalocal" could not be reached [WARNING Hostname]: hostname "rhel-node-1.novalocal": lookup rhel-node-1.novalocal on [::1]:53: read udp [::1]:48786->[::1]:53: read: connection refused [preflight] Reading configuration from the cluster... [preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml' [kubelet-start] Downloading configuration for the kubelet from the "kubelet-config-1.17" ConfigMap in the kube-system namespace [kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml" [kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env" [kubelet-start] Starting the kubelet [kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap... This node has joined the cluster: * Certificate signing request was sent to apiserver and a response was received. * The Kubelet was informed of the new secure connection details. Run 'kubectl get nodes' on the control-plane to see this node join the cluster. [root@rhel-node-1 ~]#
下面再次查看node節點
[root@rhel-master ~]# kubectl get node NAME STATUS ROLES AGE VERSION rhel-master.novalocal Ready master 8m47s v1.17.4 rhel-node-1.novalocal NotReady <none> 8m7s v1.17.4
因爲node-1節點的網絡沒有ready,下面看下pod狀態
[root@rhel-master ~]# kubectl get pod --all-namespaces -owide NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES kube-system coredns-6955765f44-9j5mc 1/1 Running 0 9m14s 10.244.0.3 rhel-master.novalocal <none> <none> kube-system coredns-6955765f44-sjsjs 1/1 Running 0 9m14s 10.244.0.2 rhel-master.novalocal <none> <none> kube-system etcd-rhel-master.novalocal 1/1 Running 0 9m31s 172.16.35.141 rhel-master.novalocal <none> <none> kube-system kube-apiserver-rhel-master.novalocal 1/1 Running 0 9m31s 172.16.35.141 rhel-master.novalocal <none> <none> kube-system kube-controller-manager-rhel-master.novalocal 1/1 Running 0 9m31s 172.16.35.141 rhel-master.novalocal <none> <none> kube-system kube-flannel-ds-s390x-ftz9h 1/1 Running 0 8m19s 172.16.35.141 rhel-master.novalocal <none> <none> kube-system kube-flannel-ds-s390x-nl5q4 0/1 Init:ErrImagePull 0 6m37s 172.16.35.138 rhel-node-1.novalocal <none> <none> kube-system kube-proxy-5vtcq 1/1 Running 0 9m14s 172.16.35.141 rhel-master.novalocal <none> <none> kube-system kube-proxy-6qfc6 1/1 Running 0 8m54s 172.16.35.138 rhel-node-1.novalocal <none> <none> kube-system kube-scheduler-rhel-master.novalocal 1/1 Running 0 9m31s 172.16.35.141 rhel-master.novalocal <none> <none> [root@rhel-master ~]#
能夠看到下rhel-node-1的flannal pod 還沒有ready ,是由於 image 的問題,我手動導入image
[root@rhel-node-1 ~]# docker load < flannelv0.12.0-s390x.tar 1f106b41b4d6: Loading layer 5.916MB/5.916MB 271ca11ef489: Loading layer 3.651MB/3.651MB fbd88a276dca: Loading layer 10.77MB/10.77MB 3b7ae8a9c323: Loading layer 2.332MB/2.332MB 4c4bfa1b47e6: Loading layer 35.23MB/35.23MB b67de7789e55: Loading layer 5.12kB/5.12kB Loaded image: quay.io/coreos/flannel:v0.12.0-s390x [root@rhel-node-1 ~]#
再次查看pod狀態
[root@rhel-master ~]# kubectl get pod --all-namespaces -owide NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES kube-system coredns-6955765f44-9j5mc 1/1 Running 0 10m 10.244.0.3 rhel-master.novalocal <none> <none> kube-system coredns-6955765f44-sjsjs 1/1 Running 0 10m 10.244.0.2 rhel-master.novalocal <none> <none> kube-system etcd-rhel-master.novalocal 1/1 Running 0 11m 172.16.35.141 rhel-master.novalocal <none> <none> kube-system kube-apiserver-rhel-master.novalocal 1/1 Running 0 11m 172.16.35.141 rhel-master.novalocal <none> <none> kube-system kube-controller-manager-rhel-master.novalocal 1/1 Running 0 11m 172.16.35.141 rhel-master.novalocal <none> <none> kube-system kube-flannel-ds-s390x-ftz9h 1/1 Running 0 9m53s 172.16.35.141 rhel-master.novalocal <none> <none> kube-system kube-flannel-ds-s390x-nl5q4 1/1 Running 0 8m11s 172.16.35.138 rhel-node-1.novalocal <none> <none> kube-system kube-proxy-5vtcq 1/1 Running 0 10m 172.16.35.141 rhel-master.novalocal <none> <none> kube-system kube-proxy-6qfc6 1/1 Running 0 10m 172.16.35.138 rhel-node-1.novalocal <none> <none> kube-system kube-scheduler-rhel-master.novalocal 1/1 Running 0 11m 172.16.35.141 rhel-master.novalocal <none> <none> [root@rhel-master ~]#
k8s 的核心組件已經部署完成!