k8s学习

To learn more about Kubernetes, here are a few advanced topics you can explore:

  1. Deployments and ReplicaSets: Learn how to manage stateless applications using Deployments and ReplicaSets.
  2. StatefulSets: Understand how to manage stateful applications.
  3. ConfigMaps and Secrets: Learn how to manage configuration data and sensitive information.
  4. Persistent Volumes and Persistent Volume Claims: Understand how to manage storage in Kubernetes.
  5. Ingress Controllers: Learn how to manage external access to services in a cluster.
  6. Helm: Explore Helm for managing Kubernetes applications.
  7. Custom Resource Definitions (CRDs): Learn how to extend Kubernetes capabilities.

1.Deployments and ReplicaSets: Learn how to manage stateless applications using Deployments and ReplicaSets.

1、安装 kubectl:

kubectl 是 Kubernetes 的命令行工具,用于与 Kubernetes 集群进行交互。
你可以通过以下命令安装 kubectl:

choco install kubernetes-cli

2、配置 kubectl:

确保 kubectl 已经配置好并指向你的 Kubernetes 集群。
你可以使用以下命令查看当前配置:

kubectl config view

3、创建一个简单的 Deployment:

创建一个 YAML 文件(例如 deployment.yaml)来定义一个 Deployment。(已经解决BUG1的版本)
示例内容如下:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      tolerations:
      - key: "node-role.kubernetes.io/control-plane"
        operator: "Exists"
        effect: "NoSchedule"
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

4、应用 Deployment:

使用 kubectl apply 命令来创建 Deployment:

kubectl apply -f deployment.yaml

5、查看 Pods:

使用以下命令查看创建的 Pods:

kubectl get pods

6、暴露 Deployment:

使用 kubectl expose 命令将 Deployment 暴露为一个服务:

kubectl expose deployment nginx-deployment --type=LoadBalancer --port=80

7、查看服务:

使用以下命令查看服务:

kubectl get services

Scale the Deployment:

kubectl scale deployment/nginx-deployment --replicas=5

8、清理资源:

完成测试后,可以删除创建的资源:

kubectl delete service nginx-deployment
kubectl delete deployment nginx-deployment

BUG1: 1 node(s) had untolerated taint {node-role.kubernetes.io/control-plane

Warning  FailedScheduling  69s (x2 over 6m9s) 
default-scheduler  0/1 nodes are available: 
1 node(s) had untolerated taint {node-role.kubernetes.io/control-plane: }. 
preemption: 0/1 nodes are available: 1 Preemption is not helpful for scheduling.
根据 kubectl describe pod 的输出,
Pods 处于 Pending 状态的原因是没有可用的节点可以调度这些 Pods。
具体来说,所有节点都有一个 taint {node-role.kubernetes.io/control-plane: },
而这些 Pods 没有相应的 toleration 来容忍这个 taint。
什么是 Taint 和 Toleration?
Taint:
Taint 是一种机制,用于防止 Pods 被调度到某些节点上。
节点可以被标记为具有特定的 taint,
这样只有具有相应 toleration 的 Pods 才能被调度到这些节点上。

Toleration:
Toleration 是 Pods 的属性,用于声明它们可以容忍某些 taint,
从而允许它们被调度到具有这些 taint 的节点上。

问题的原因
根据 kubectl describe pod 的输出,你的 Pods 处于 Pending 状态,
因为没有可用的节点可以调度这些 Pods。
具体来说,所有节点都有一个 taint {node-role.kubernetes.io/control-plane: },
而这些 Pods 没有相应的 toleration 来容忍这个 taint。

你有两种选择来解决这个问题:

方法一:移除节点的 Taint

如果你希望在控制平面节点上运行 Pods,可以移除这个 taint。这样,Pods 就可以被调度到这些节点上。

kubectl taint nodes --all node-role.kubernetes.io/control-plane-

方法二:为 Pods 添加 Toleration

如果你希望 Pods 能够容忍这个 taint,可以在 Deployment 的 YAML 文件中添加相应的 toleration。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      tolerations:
      - key: "node-role.kubernetes.io/control-plane"
        operator: "Exists"
        effect: "NoSchedule"
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80

3、重新应用 Deployment:
更新 Deployment 文件后,重新应用它。

kubectl apply -f deployment.yaml

检查节点状态:

确保集群中有可用的节点,并且节点处于 Ready 状态。

kubectl get nodes

查看 Pod 的事件日志:

查看 Pod 的事件日志以获取更多详细信息。

kubectl describe pod <pod-name>

BUG2: nginx-deployment 的 EXTERNAL-IP 显示为 pending

[root@kube-master test_k8s]# kubectl get services

NAME               TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE

kubernetes         ClusterIP      10.96.0.1       <none>        443/TCP        5d16h

nginx-deployment   LoadBalancer   10.97.157.228   <pending>     80:30956/TCP   6s

方法一:使用 NodePort 类型的服务

如果你的集群不支持 LoadBalancer 类型的服务,可以使用 NodePort 类型的服务。这样,你可以通过集群节点的 IP 地址和指定的端口访问服务。
1、删除现有的服务:

kubectl delete service nginx-deployment

2、创建 NodePort 类型的服务:

kubectl expose deployment nginx-deployment --type=NodePort --port=80

3、检查服务:

kubectl get services
[root@kube-master ~]# kubectl get services

NAME               TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE

kubernetes         ClusterIP   10.96.0.1        <none>        443/TCP        5d23h

nginx-deployment   NodePort    10.100.180.176   <none>        80:32343/TCP   6h

2.StatefulSets: Understand how to manage stateful applications.

Sure! Let’s analyze the core features of StatefulSets, focusing on stable identities and persistent storage, using the provided YAML configuration.

StatefulSet YAML

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: web
spec:
  serviceName: "nginx"
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
  volumeClaimTemplates:
  - metadata:
      name: www
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 1Gi

Analysis

Stable Identities

StatefulSet: Manages the deployment and scaling of a set of Pods, 
and provides guarantees about the ordering and uniqueness of these Pods.
Pod Naming: Each Pod in a StatefulSet gets a unique, 
stable network identity. The Pods are named with a predictable pattern: 
$(statefulset name)-$(ordinal). 
For example, the Pods will be named web-0, web-1, web-2.
metadata:
  name: web
spec:
  serviceName: "nginx"
  replicas: 3
serviceName: The name of the headless service 
that controls the network identity of the Pods.
replicas: The number of desired Pods. In this case, 3 replicas will be created.

Persistent Storage

volumeClaimTemplates: 
Defines the PersistentVolumeClaims (PVCs) for the StatefulSet. 
Each Pod in the StatefulSet will get its own PVC, 
ensuring that each Pod has its own persistent storage.
volumeClaimTemplates:
- metadata:
    name: www
  spec:
    accessModes: [ "ReadWriteOnce" ]
    resources:
      requests:
        storage: 1Gi
metadata.name: The name of the PVC. 
Each Pod will get a PVC with a unique name based on this template 
(e.g., www-web-0, www-web-1, www-web-2).

accessModes: Specifies the access mode for the volume. 
ReadWriteOnce means the volume can be mounted as read-write by a single node.

resources.requests.storage: Specifies the amount of storage requested for each PVC.
In this case, each PVC will request 1Gi of storage.

Summary

Stable Identities: Each Pod in the StatefulSet has a unique,
stable network identity, 
which is crucial for stateful applications that require stable network identities.

Persistent Storage: Each Pod gets its own PersistentVolumeClaim,
ensuring that data is not lost when Pods are rescheduled. 
This is essential for stateful applications that require persistent storage.
### 回答1: 《K8S学习指南PDF》是一本非常有用的指南,它为初学者提供了一份清晰明了的指南,帮助他们学习K8S的基本概念、架构和运作方式。这本指南对于那些希望学习Kubernetes技术并开始构建容器化应用程序的人来说非常重要。在这本指南中,读者可以了解到Kubernetes的主要特点,包括它如何管理和调度容器,并将这些容器部署到集群中。 此外,这本指南还介绍了Kubernetes的核心组件和它们的作用,例如etcd、kube-apiserver、kube-controller-manager、kube-scheduler和kubelet。阅读本指南后,读者将了解到这些组件如何协同工作,以及它们是如何创建、管理和监视容器化应用程序的。 除此之外,《K8S学习指南PDF》还讨论了Kubernetes的一些高级概念,例如自动伸缩、滚动更新和容器网络(CNI)。这些概念将有助于读者充分理解Kubernetes如何支持现代应用程序开发的需求,包括动态伸缩、A/B 测试和分布式应用程序。 总而言之,《K8S学习指南PDF》是一份非常有价值的指南,适合那些想要学习Kubernetes容器化技术的人使用。它提供了深入浅出的介绍,为读者提供了一个良好的理解Kubernetes容器化这一创新技术的基础。 ### 回答2: Kubernetesk8s)是一种流行的容器编排系统,能够自动管理和部署容器化应用程序。而"k8s学习指南"是一本面向初学者的指南性书籍,旨在帮助读者了解Kubernetes技术。本书包含了Kubernetes的基础概念、架构、核心组件、资源对象等核心知识点,并通过多个实践、案例,帮助读者深入了解Kubernetes应用的实际操作过程。总之,该书的重点在于让读者系统地学习和理解Kubernetes的各个方面,为他们快速掌握这一技术打下坚实的基础。 以下是本书的主要内容简介: 第一章介绍了Kubernetes的核心概念及背景知识,以及容器化技术的概述。 第二章重点介绍了Kubernetes的架构、组件、工作原理等核心知识点; 第三章详细解析Kubernetes的核心概念和术语,如:pod、service、replication controller、deployment、statefulset、cronjob等。 第四章介绍了如何安装、配置和使用Kubernetes,包括使用Minikube和Kubernetes in Docker(KinD)进行本地测试等。 第五章介绍了Kubernetes的网络和存储,包括服务发现、负载均衡等不同方面的网络设置。 第六章介绍了Kubernetes的日志和监控,如何生成和收集日志、如何监控Kubernetes集群和应用程序等。 总的来说,这本书对于初学者来说非常友好,通过简单易懂的表述和大量实践案例的引入,能够帮助读者轻松地掌握Kubernetes技术。 ### 回答3: k8s学习指南PDF是一份帮助初学者了解Kubernetes的指南手册。需要指出的是,Kubernetes被广泛认为是容器编排中最好的开源平台,它允许在虚拟或物理机器集群中管理容器化应用程序。它提供了一个简单而可靠的平台,用于快速的容器化应用程序。在这个PDF指南中,使用者将学习Kubernetes的基础知识,例如Kubernetes的核心构建块,如Pod,ReplicaSet,Deployment等。此外,学习者还将了解如何配置Kubernetes集群,并了解如何使用Kubernetes的持久化存储,例如ConfigMaps和Secrets来管理配置和敏感数据。它还将讨论如何使用Ingress控制器来公开Kubernetes中的服务。学习者可以理解rkt和Docker这两种容器运行时集成Kubernetes的方式以及如何将容器注册到Kubernetes中。除了这些基础知识,学习者还可以了解如何使用Kubernetes的一些应用程序开发和管理工具,例如Helm和Kubectl。总之,这个Kubernetes学习指南PDF为初学者提供了一个全面的指南,其中详细解释了Kubernetes的所有基础知识和工具。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值