kubernetes容器集群管理启动一个测试示例

创建nginx

创建3个nginx副本
[[email protected] bin]# kubectl run nginx --image=nginx --replicas=3
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
deployment.apps/nginx created
查看创建的容器
[[email protected] bin]# kubectl get pod
NAME                     READY   STATUS              RESTARTS   AGE
nginx-7bb7cd8db5-4h2wn   0/1     ImagePullBackOff    0          67s
nginx-7bb7cd8db5-kgsxt   0/1     ContainerCreating   0          67s
nginx-7bb7cd8db5-tjw54   0/1     ImagePullBackOff    0          67s
查看所有资源对象
[[email protected] bin]# kubectl get pod
NAME                     READY   STATUS              RESTARTS   AGE
nginx-7bb7cd8db5-4h2wn   0/1     ImagePullBackOff    0          67s
nginx-7bb7cd8db5-kgsxt   0/1     ContainerCreating   0          67s
nginx-7bb7cd8db5-tjw54   0/1     ImagePullBackOff    0          67s
[[email protected] bin]# kubectl get all
NAME                         READY   STATUS             RESTARTS   AGE
pod/nginx-7bb7cd8db5-4h2wn   0/1     ImagePullBackOff   0          2m47s
pod/nginx-7bb7cd8db5-kgsxt   0/1     ImagePullBackOff   0          2m47s
pod/nginx-7bb7cd8db5-tjw54   0/1     ImagePullBackOff   0          2m47s

NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.10.10.1   <none>        443/TCP   9d

NAME                          READY   UP-TO-DATE   AVAILABLE   AGE
deployment.extensions/nginx   0/3     3            0           2m47s

NAME                                     DESIRED   CURRENT   READY   AGE
replicaset.extensions/nginx-7bb7cd8db5   3         3         0       2m47s

NAME                    READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/nginx   0/3     3            0           2m47s

NAME                               DESIRED   CURRENT   READY   AGE
replicaset.apps/nginx-7bb7cd8db5   3         3         0       2m47s
[[email protected] bin]# kubectl get all
NAME                         READY   STATUS    RESTARTS   AGE
pod/nginx-7bb7cd8db5-4h2wn   1/1     Running   0          11m
pod/nginx-7bb7cd8db5-kgsxt   1/1     Running   0          11m
pod/nginx-7bb7cd8db5-tjw54   1/1     Running   0          11m

NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.10.10.1   <none>        443/TCP   9d

NAME                          READY   UP-TO-DATE   AVAILABLE   AGE
deployment.extensions/nginx   3/3     3            3           11m

NAME                                     DESIRED   CURRENT   READY   AGE
replicaset.extensions/nginx-7bb7cd8db5   3         3         3       11m

NAME                    READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/nginx   3/3     3            3           11m

NAME                               DESIRED   CURRENT   READY   AGE
replicaset.apps/nginx-7bb7cd8db5   3         3         3       11m
[[email protected] bin]# kubectl get pod
NAME                     READY   STATUS    RESTARTS   AGE
nginx-7bb7cd8db5-4h2wn   1/1     Running   0          12m
nginx-7bb7cd8db5-kgsxt   1/1     Running   0          12m
nginx-7bb7cd8db5-tjw54   1/1     Running   0          12m
查看容器运行主机位置
[[email protected] bin]# kubectl get pod -o wide
NAME                     READY   STATUS    RESTARTS   AGE   IP            NODE              NOMINATED NODE   READINESS GATES
nginx-7bb7cd8db5-4h2wn   1/1     Running   0          13m   172.17.54.2   192.168.238.128   <none>           <none>
nginx-7bb7cd8db5-kgsxt   1/1     Running   0          13m   172.17.10.3   192.168.238.129   <none>           <none>
nginx-7bb7cd8db5-tjw54   1/1     Running   0          13m   172.17.10.2   192.168.238.129   <none>           <none>
发布服务
[[email protected] bin]# kubectl expose deployment nginx --port=88 --target-port=80 --type=NodePort
service/nginx exposed
[[email protected] bin]# kubectl get pod
NAME                     READY   STATUS    RESTARTS   AGE
nginx-7bb7cd8db5-4h2wn   1/1     Running   0          17m
nginx-7bb7cd8db5-kgsxt   1/1     Running   0          17m
nginx-7bb7cd8db5-tjw54   1/1     Running   0          17m
[[email protected] bin]# kubectl get svc
NAME         TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP   10.10.10.1    <none>        443/TCP        9d
nginx        NodePort    10.10.10.40   <none>        88:30879/TCP   71s
node节点访问测试
[[email protected] ~]# curl 10.10.10.40:88
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

浏览器访问测试

查看日志
[[email protected] bin]# kubectl get pod
NAME                     READY   STATUS    RESTARTS   AGE
nginx-7bb7cd8db5-4h2wn   1/1     Running   0          22m
nginx-7bb7cd8db5-kgsxt   1/1     Running   0          22m
nginx-7bb7cd8db5-tjw54   1/1     Running   0          22m
[[email protected] bin]# kubectl logs nginx-7bb7cd8db5-4h2wn
172.17.10.0 - - [17/Jul/2019:00:25:12 +0000] "GET / HTTP/1.1" 200 612 "-" "curl/7.29.0" "-"
查看已经部署的容器
[[email protected] ~]# kubectl get deployment
NAME    READY   UP-TO-DATE   AVAILABLE   AGE
nginx   3/3     3            3           2d
删除部署的容器
[[email protected] ~]# kubectl delete deployment nginx
deployment.extensions "nginx" deleted
[[email protected] ~]# kubectl get deployment
No resources found.

原文地址:https://www.cnblogs.com/yinshoucheng-golden/p/11219079.html

时间: 2024-10-09 20:53:50

kubernetes容器集群管理启动一个测试示例的相关文章

Kubernetes容器集群管理环境 - Node节点的移除与加入

一.如何从Kubernetes集群中移除Node 比如从集群中移除k8s-node03这个Node节点,做法如下: 1)先在master节点查看Node情况 [[email protected]-master01 ~]# kubectl get nodes NAME STATUS ROLES AGE VERSION k8s-node01 Ready <none> 47d v1.14.2 k8s-node02 Ready <none> 47d v1.14.2 k8s-node03 R

kubernetes容器集群管理部署master节点组件

集群部署获取k8s二进制包 [[email protected] ~]# wget https://dl.k8s.io/v1.15.0/kubernetes-server-linux-amd64.tar.gz [[email protected] ~]# ls kubernetes-server-linux-amd64.tar.gz [[email protected] ~]# mkdir master [[email protected] ~]# mv kubernetes-server-li

Kubernetes(k8s)集群部署(k8s企业级Docker容器集群管理)系列之部署master/node节点组件(四)

0.前言 整体架构目录:ASP.NET Core分布式项目实战-目录 k8s架构目录:Kubernetes(k8s)集群部署(k8s企业级Docker容器集群管理)系列目录 1.部署master组件 master 服务器的组件有:kube-apiserver.kube-controller-manager.kube-scheduler 因此需要下载k8s master,下载地址:https://github.com/kubernetes/kubernetes/blob/master/CHANGE

Docker&Kubernetes沙龙干货集锦:容器集群管理利器kubernetes详谈-CSDN.NET

Docker&Kubernetes沙龙干货集锦:容器集群管理利器kubernetes详谈-CSDN.NET undefined Package - crawler undefined Docker&Kubernetes沙龙干货集锦:容器集群管理利器kubernetes详谈-CSDN.NET

Kubernetes(K8s)(二)——搭建Kubernetes容器集群管理系统

(1).配置说明 节点角色 IP地址 CPU 内存 master.etcd 192.168.128.110 4核 2G node1/minion1 192.168.128.111 4核 2G node2/minion2 192.168.128.112 4核 2G (2).搭建Kubernetes容器集群管理系统 1)三台主机安装常用的软件包 bash-completion可以使得按<Tab>键补齐,vim是vi编辑器的升级版,wget用于下载阿里云的yum源文件. # yum -y insta

容器集群管理平台的比较

容器化和微服务是当前最热话题,不久之前,笔者(据说因为现在都不用笔了,"笔者"的称谓已经不合适了,因为输入用键盘,叫"键人"更为合适)参加QCon上海一个微服务监控的Session,场面爆棚,我不得不在拥挤的过道听完了整个session.随着要管理的容器越来越多,容器的集群管理平台成为了刚需! Docker Swarm Swarm是Docker公司在2014年12月初新发布的容器集群管理工具.它可以把多个主机变成一个虚拟的Docker主机来管理.Swarm使用Go语

Docker全新的容器集群项目——SwarmKit初步测试

题记 对于Docker容器集群来说,比较成熟的方案包括Swarm.Mesos.k8s和Google的Kubernetes,特别是后者得到了更多厂商的使用和推广,但是kubernetes相比较来说技术门槛较高,让很多用户望而却步,幸好,Docker在今年的6月7号开源发布了原生的集群管理工具SwarmKit,主要提供容器集群以及编排能力,那赶紧尝试一下,看看有什么好的功能. SwarmKit框架 SwarmKit中有两种角色,Manager和Worker.Manager主要管理节点.调度任务.Wo

Swarm容器集群管理(介绍)

一.Swarm介绍 Swarm是Docker公司自研发的容器集群管理系统, Swarm在早期是作为一个独立服务存在, 在Docker Engine v1.12中集成了Swarm的集群管理和编排功能.可以通过初始化Swarm或加入现有Swarm来启用Docker引擎的Swarm模式. Docker Engine CLI和API包括了管理Swarm节点命令,比如添加.删除节点,以及在Swarm中部署和编排服务.也增加了服务栈(Stack).服务(Service).任务(Task)概念. 二.Swar

10分钟快速搭建Kubernetes容器集群平台

官方提供Kubernetes部署3种方式 minikube Minikube是一个工具,可以在本地快速运行一个单点的Kubernetes,尝试Kubernetes或日常开发的用户使用.不能用于生产环境. 官方文档:https://kubernetes.io/docs/setup/minikube/ kubeadm kubeadm可帮助你快速部署一套kubernetes集群.kubeadm设计目的为新用户开始尝试kubernetes提供一种简单的方法.目前是Beta版. 官方文档:https://