kubeadm 部署kubernetes 1.11.0 的问题记录

系统环境

[root@kubeadm ~]# cat /etc/redhat-release 
CentOS Linux release 7.5.1804 (Core) 

关闭selinux

[root@kubeadm ~]# cat /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 

编辑kubelet的启动环境变量,该变量要与docker的cgroup-driver驱动一样

docker的cgroup-driver驱动

[root@kubeadm ~]# docker info
Containers: 10
 Running: 10
 Paused: 0
 Stopped: 0
Images: 7
Server Version: 1.13.1
Storage Driver: overlay2
 Backing Filesystem: xfs
 Supports d_type: true
 Native Overlay Diff: false
Logging Driver: journald
Cgroup Driver: systemd

kubelet的cgroup-driver驱动

[root@kubeadm ~]# cat /etc/default/kubelet 
KUBELET_KUBEADM_EXTRA_ARGS=--cgroup-driver=systemd

安装docker

yum install -y docker
systemctl enable docker && systemctl start docker

添加谷歌的yum源

[root@kubeadm ~]# cat /etc/yum.repos.d/kubernetes.repo 
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg

安装kubelet kubeadm kubectl

yum install -y kubelet kubeadm kubectl
systemctl enable kubelet

注意:这一步不能直接执行 systemctl start kubelet,否侧会报错,kubelet也起动不成功

729 12:17:19 kubeadm systemd[1]: Started kubelet: The Kubernetes Node Agent.
729 12:17:19 kubeadm systemd[1]: Starting kubelet: The Kubernetes Node Agent...
729 12:17:20 kubeadm kubelet[32751]: F0729 12:17:20.026220   32751 server.go:190] failed to load Kubelet config file /var/lib/kubelet/config.yaml, error failed to read kubelet config file "/var/lib/kubelet/config.yaml", error: open /var/lib/kubelet/config.yaml: no such file or directory

相关文章

直接执行

[root@kubeadm ~]# kubeadm init
[init] using Kubernetes version: v1.11.1
[preflight] running pre-flight checks
    [WARNING Firewalld]: firewalld is active, please ensure ports [6443 10250] are open or your cluster may not function correctly
I0729 12:24:37.097036     574 kernel_validator.go:81] Validating kernel version
I0729 12:24:37.097124     574 kernel_validator.go:96] Validating kernel config
    [WARNING Hostname]: hostname "kubeadm" could not be reached
    [WARNING Hostname]: hostname "kubeadm" lookup kubeadm on 10.155.0.1:53: no such host
[preflight/images] Pulling images required for setting up a Kubernetes cluster
[preflight/images] This might take a minute or two, depending on the speed of your internet connection
[preflight/images] You can also perform this action in beforehand using 'kubeadm config images pull'

[kubelet] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[preflight] Activating the kubelet service
[certificates] Generated ca certificate and key.
[certificates] Generated apiserver certificate and key.
[root@kubeadm ~]# systemctl status kubelet
● kubelet.service - kubelet: The Kubernetes Node Agent
   Loaded: loaded (/etc/systemd/system/kubelet.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/kubelet.service.d
           └─10-kubeadm.conf
   Active: active (running) since 日 2018-07-29 12:27:18 CST; 1min 10s ago
     Docs: http://kubernetes.io/docs/
 Main PID: 917 (kubelet)
   CGroup: /system.slice/kubelet.service
           └─917 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --config=/var/lib...

7月 29 12:28:10 kubeadm kubelet[917]: W0729 12:28:10.689546     917 cni.go:172] Unable to update cni config: No networks found in /etc/cni/net.d
729 12:28:10 kubeadm kubelet[917]: E0729 12:28:10.689653     917 kubelet.go:2110] Container runtime network not ready: NetworkReady=false reas...itialized
729 12:28:15 kubeadm kubelet[917]: W0729 12:28:15.691030     917 cni.go:172] Unable to update cni config: No networks found in /etc/cni/net.d
729 12:28:15 kubeadm kubelet[917]: E0729 12:28:15.691284     917 kubelet.go:2110] Container runtime network not ready: NetworkReady=false reas...itialized
729 12:28:20 kubeadm kubelet[917]: E0729 12:28:20.683083     917 summary.go:102] Failed to get system container stats for "/system.slice/kubelet.servic...
7月 29 12:28:20 kubeadm kubelet[917]: E0729 12:28:20.683103     917 summary.go:102] Failed to get system container stats for "/system.slice/docke....service"
7月 29 12:28:20 kubeadm kubelet[917]: W0729 12:28:20.692520     917 cni.go:172] Unable to update cni config: No networks found in /etc/cni/net.d
7月 29 12:28:20 kubeadm kubelet[917]: E0729 12:28:20.692688     917 kubelet.go:2110] Container runtime network not ready: NetworkReady=false reas...itialized
7月 29 12:28:25 kubeadm kubelet[917]: W0729 12:28:25.694158     917 cni.go:172] Unable to update cni config: No networks found in /etc/cni/net.d
7月 29 12:28:25 kubeadm kubelet[917]: E0729 12:28:25.694261     917 kubelet.go:2110] Container runtime network not ready: NetworkReady=false reas...itialized
Hint: Some lines were ellipsized, use -l to show in full.

后续跟之后的和低版本的部署都是一样的了,在这里就不详细讲了

参考
install-kubeadm

以下是 Hyperf 官方提供的通过 Kubernetes 实现容器化部署的文档,供您参考: 1. 部署环境要求 - 操作系统:Linux - Docker:18.06.0-ce 或更高版本 - Kubernetes1.11.0 或更高版本 2. 部署步骤 2.1 创建 Docker 镜像 首先,您需要创建一个 Docker 镜像,该镜像包含了 Hyperf 应用程序以及其依赖项。您可以使用 Dockerfile 来定义镜像的构建过程。示例 Dockerfile 如下: ``` FROM php:7.4-fpm # 安装依赖 RUN apt-get update && \ apt-get install -y git zip unzip && \ docker-php-ext-install pdo_mysql && \ pecl install redis && \ docker-php-ext-enable redis # 安装 Composer COPY --from=composer:latest /usr/bin/composer /usr/bin/composer # 复制 Hyperf 应用程序 COPY . /var/www # 安装依赖项 WORKDIR /var/www RUN composer install # 暴露端口 EXPOSE 9501 # 启动命令 CMD ["php", "bin/hyperf.php", "start"] ``` 其中,我们使用了 `php:7.4-fpm` 作为基础镜像,安装了 Hyperf 应用程序所需的依赖项,并将应用程序复制到了 `/var/www` 目录中。我们还使用了 Composer 安装了应用程序的依赖项,并暴露了端口 `9501`。在启动容器时,我们使用了 `php bin/hyperf.php start` 命令来启动 Hyperf 应用程序。您可以根据实际情况修改 Dockerfile。 然后,使用以下命令构建 Docker 镜像: ``` docker build -t your-image-name . ``` 其中,`your-image-name` 是您的镜像名称。 2.2 创建 Kubernetes 部署文件 接下来,您需要创建 Kubernetes部署文件,该文件定义了如何部署 Hyperf 应用程序。示例部署文件如下: ```yaml apiVersion: apps/v1 kind: Deployment metadata: name: your-deployment-name labels: app: your-app-name spec: replicas: 3 selector: matchLabels: app: your-app-name template: metadata: labels: app: your-app-name spec: containers: - name: your-container-name image: your-image-name ports: - name: http containerPort: 9501 ``` 其中,您需要修改以下部分: - `your-deployment-name`:您的部署名称。 - `your-app-name`:您的应用程序名称。 - `your-container-name`:您的容器名称。 - `your-image-name`:您的 Docker 镜像名称。 该部署文件定义了一个名为 `your-deployment-name` 的部署,使用了名为 `your-image-name` 的 Docker 镜像,并将端口 `9501` 暴露出来。该部署文件还定义了应用程序的副本数为 `3`。 2.3 创建 Kubernetes 服务文件 接下来,您需要创建 Kubernetes 的服务文件,该文件定义了如何访问 Hyperf 应用程序。示例服务文件如下: ```yaml apiVersion: v1 kind: Service metadata: name: your-service-name spec: selector: app: your-app-name ports: - name: http port: 80 targetPort: http type: LoadBalancer ``` 其中,您需要修改以下部分: - `your-service-name`:您的服务名称。 - `your-app-name`:您的应用程序名称。 该服务文件定义了一个名为 `your-service-name` 的服务,使用了应用程序名称为 `your-app-name` 的部署。该服务将端口 `80` 映射到了端口 `9501`,并使用了负载均衡器。 2.4 部署应用程序 最后,使用以下命令部署应用程序: ``` kubectl apply -f your-deployment-file.yaml kubectl apply -f your-service-file.yaml ``` 其中,`your-deployment-file.yaml` 和 `your-service-file.yaml` 分别是您的部署文件和服务文件。 部署完成后,您可以使用以下命令查看服务的 IP 地址和端口号: ``` kubectl get services ``` 然后,您可以使用浏览器或其他工具访问 Hyperf 应用程序。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值