赞
踩
kubectl run 自定义pod名字 --image=基础镜像
[root@VM-4-8-centos kubernetes]# kubectl run my-nginx --image=nginx
pod/my-nginx created
[root@VM-4-8-centos ~]# kubectl get pod -n default
NAME READY STATUS RESTARTS AGE
my-nginx 1/1 Running 0 15s
kubectl get pod podName -owide
[root@VM-4-8-centos ~]# kubectl get pod my-nginx -owide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
my-nginx 1/1 Running 0 2m30s 10.244.0.9 vm-4-8-centos <none> <none>
kubectl describe pod podName
[root@VM-4-8-centos ~]# kubectl describe pod my-nginx Name: my-nginx Namespace: default Priority: 0 Node: vm-4-8-centos/10.0.4.8 Start Time: Sat, 26 Feb 2022 11:25:56 +0800 Labels: run=my-nginx Annotations: <none> ... Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 3m41s default-scheduler Successfully assigned default/my-nginx to vm-4-8-centos Normal Pulling 3m41s kubelet Pulling image "nginx" Normal Pulled 3m40s kubelet Successfully pulled image "nginx" in 882.15599ms Normal Created 3m40s kubelet Created container my-nginx Normal Started 3m40s kubelet Started container my-nginx
kubectl logs podName
[root@VM-4-8-centos ~]# kubectl logs my-nginx
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
...
2022/02/26 03:25:57 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2022/02/26 03:25:57 [notice] 1#1: start worker processes
2022/02/26 03:25:57 [notice] 1#1: start worker process 31
2022/02/26 03:25:57 [notice] 1#1: start worker process 32
通过kubectl get pod podName -owide
可以获取pod的IP地址,那么就可以访问Pod中的容器进程;
[root@VM-4-8-centos ~]# curl http://10.244.0.9
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
...
<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>
kubectl exec -it podName -- /bin/bash
[root@VM-4-8-centos ~]# kubectl exec -it my-nginx -- /bin/bash
root@my-nginx:/# cd /usr/share/nginx/html/
root@my-nginx:/usr/share/nginx/html# ll
bash: ll: command not found
root@my-nginx:/usr/share/nginx/html# ls
50x.html index.html
root@my-nginx:/usr/share/nginx/html# echo "welcome my nginx pod" > index.html
kubectl delete pod Pod名称 -n 指定命名空间
[root@VM-4-8-centos kubernetes]# kubectl delete pod my-nginx -n default
pod "my-nginx" deleted
vi pod-demo.yaml
# 内容如下
apiVersion: v1
kind: Pod # 资源类型,Pod
metadata: # 元数据
name: nginx01 # Pod自定义名称
namespace: default # 命名空间
labels: # 标签
run: nginx01
spec: # 配置信息
containers: # 容器组
- name: nginx01 # 容器名字
image: nginx # 指定基础镜像名字或者仓库连接
[root@VM-4-8-centos kubernetes]# kubectl apply -f pod-demo.yaml
[root@VM-4-8-centos kubernetes]# kubectl delete -f pod-demo.yaml
选择在默认namespace=default中新建Pod,控制面板中选择yaml格式文件创建,内容与命令终端创建格式一样;
Pod菜单中可以查看目录
其他的操作小编就不再详细介绍了,管理图形化界面相信大家都可以搞定的~
学习Pod的时候,大家都应该清楚,Pod是一个容器组,其中可以包含多个容器,那么我们接下来创建一个多容器的Pod;
新增Tomcat容器
apiVersion: v1
kind: Pod # 资源类型,Pod
metadata: # 元数据
name: pod-demo1 # Pod自定义名称
namespace: default # 命名空间
labels: # 标签
run: pod-demo1
spec: # 配置信息
containers: # 容器组
- name: nginx # 容器名字
image: nginx # 指定基础镜像名字或者仓库连接
- name: tomcat
image: tomcat:8.5.68
上传完之后,可以看到我们的pod已经运行
pod目录列表每行最后三个点下拉列表中选择执行
进入操作的容器;
分别访问Nginx和Tomcat;
格式podIP+容器端口
[root@VM-4-8-centos ~]# kubectl get pod pod-demo1 -owide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod-demo1 2/2 Running 0 9m37s 10.244.0.11 vm-4-8-centos <none> <none>
[root@VM-4-8-centos ~]# curl http://10.244.0.11
hello nginx
[root@VM-4-8-centos ~]# curl http://10.244.0.11:8080
<!doctype html><html lang="en"><head><title>HTTP Status 404 – Not Found</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 404 – Not Found</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Description</b> The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.</p><hr class="line" /><h3>Apache Tomcat/8.5.68</h3></body></html>[root@VM-4-8-centos ~]#
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。