1. 程式人生 > >k8s Docker 安裝

k8s Docker 安裝

# k8s Docker 安裝 # 一、執行環境 > Centos 7.7 > 虛擬機器核心為 3.10 > 基礎元件版本: > k8s.gcr.io/kube-apiserver:v1.16.0 > k8s.gcr.io/kube-controller-manager:v1.16.0 > k8s.gcr.io/kube-scheduler:v1.16.0 > k8s.gcr.io/kube-proxy:v1.16.0 > k8s.gcr.io/pause:3.1 > k8s.gcr.io/etcd:3.3.15-0 > k8s.gcr.io/coredns:1.6.2 | hostname | ip | resource | role | | --- | --- | --- | --- | | hsjry-16-114-128 | 172.16.114.128 | 2c2G | master | | hsjry-16-114-129 | 172.16.114.129 | 2c2G | node1 | | hsjry-16-114-130 | 172.16.114.130 | 2c2G | node2 | # 二、介質準備 需要下載安裝 docker 所需要的依賴和 docker 本身。
需要下載上述元件的映象包
準備 kubeadm kubectl kubelet ```shell cat > /etc/yum.repos.d/kubernetes.repo <> /etc/docker/daemon.json { "exec-opts": ["native.cgroupdriver=systemd"], "insecure-registries": ["0.0.0.0/0"] } EOF systemctl restart docker ``` # 四、安裝 kubernetes ## 1.前期配置 這個階段的內容需要在各個節點上執行 ```shell base_dir=./k8s # 載入核心引數 modprobe -- ip_vs modprobe -- ip_vs_rr modprobe -- ip_vs_wrr modprobe -- ip_vs_sh if [[ $(uname -r |cut -d . -f1) -ge 4 && $(uname -r |cut -d . -f2) -ge 19 ]]; then modprobe -- nf_conntrack else modprobe -- nf_conntrack_ipv4 fi cat < /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF # 立即生效 sysctl --system sysctl -w net.ipv4.ip_forward=1 systemctl stop firewalld && systemctl disable firewalld swapoff -a || true setenforce 0 || true # 這裡是將下載好的直接 cp,也可選擇 rpm 安裝的方式 chmod a+x $base_dir/bin/* cp $base_dir/bin/* /usr/bin cp $base_dir/conf/kubelet.service /etc/systemd/system/ mkdir /etc/systemd/system/kubelet.service.d cp $base_dir/conf/10-kubeadm.conf /etc/systemd/system/kubelet.service.d/ # 獲取 docker 的 cgroupDriver cgroupDriver=$(docker info|grep Cg) driver=${cgroupDriver##*: } echo "driver is ${driver}" mkdir -p /var/lib/kubelet/ || true # 宣告 kubelete 的配置內容 cat < /var/lib/kubelet/config.yaml address: 0.0.0.0 apiVersion: kubelet.config.k8s.io/v1beta1 authentication: anonymous: enabled: false webhook: cacheTTL: 2m0s enabled: true x509: clientCAFile: /etc/kubernetes/pki/ca.crt authorization: mode: Webhook webhook: cacheAuthorizedTTL: 5m0s cacheUnauthorizedTTL: 30s cgroupDriver: ${driver} cgroupsPerQOS: true clusterDNS: - 10.96.0.10 clusterDomain: cluster.local configMapAndSecretChangeDetectionStrategy: Watch containerLogMaxFiles: 5 containerLogMaxSize: 10Mi contentType: application/vnd.kubernetes.protobuf cpuCFSQuota: true cpuCFSQuotaPeriod: 100ms cpuManagerPolicy: none cpuManagerReconcilePeriod: 10s enableControllerAttachDetach: true enableDebuggingHandlers: true enforceNodeAllocatable: - pods eventBurst: 10 eventRecordQPS: 5 evictionHard: imagefs.available: 15% memory.available: 100Mi nodefs.available: 10% nodefs.inodesFree: 5% evictionPressureTransitionPeriod: 5m0s failSwapOn: true fileCheckFrequency: 20s hairpinMode: promiscuous-bridge healthzBindAddress: 127.0.0.1 healthzPort: 10248 httpCheckFrequency: 20s imageGCHighThresholdPercent: 85 imageGCLowThresholdPercent: 80 imageMinimumGCAge: 2m0s iptablesDropBit: 15 iptablesMasqueradeBit: 14 kind: KubeletConfiguration kubeAPIBurst: 10 kubeAPIQPS: 5 makeIPTablesUtilChains: true maxOpenFiles: 1000000 maxPods: 110 nodeLeaseDurationSeconds: 40 nodeStatusUpdateFrequency: 10s oomScoreAdj: -999 podPidsLimit: -1 port: 10250 registryBurst: 10 registryPullQPS: 5 resolvConf: /etc/resolv.conf rotateCertificates: true runtimeRequestTimeout: 2m0s serializeImagePulls: true staticPodPath: /etc/kubernetes/manifests streamingConnectionIdleTimeout: 4h0m0s syncFrequency: 1m0s volumeStatsAggPeriod: 1m0s EOF # 載入映象包 docker load -i $base_dir/images/images.tar.gz || true systemctl enable kubelet ``` ## 2.初始化 master 本次通過 kubeadm 的方式初始化 master 節點 ```shell base_dir=./k8s kubeadm init --config $base_dir/conf/kubeadm.yaml mkdir ~/.kube cp /etc/kubernetes/admin.conf ~/.kube/config kubectl taint nodes --all node-role.kubernetes.io/master- kubectl apply -f $base_dir/conf/kube-flannel.yaml sleep 5 kubectl apply -f $base_dir/conf/traefik-config.yaml ``` 這裡結束後會輸出一個命令,需要 cp 這個命令到 node 節點上敲下,就可以加入master 了 ## 2.初始化 node ```shell # 需執行上述 1 的內容 # 通過 kubeadm create token 建立的 token ,過期時間是24小時,這就是為什麼過了一天無法再次使用之前記錄的 kube join 原生指令碼的原因,也可以執行 kubeadm token create --ttl 0生成一個永不過期的 token, ``` ## 4.驗證 到 master 節點上敲 kubectl get nodes 就可以看到這個叢集的資訊咯
# 五、安裝 ingress 這裡採用 [traefix](https://docs.traefik.io/) 來作為服務暴露的方式。
`kubectl apply -f $base_dir/conf/traefik-config.yaml` # 六、附件 [github](https://github.com/ankuo/k8s-install)