如上图所示,Pod的使用方式通常包含两种:
Pod中运行一个容器,最经常使用的模式,Container封装在pod中调度,两者几乎等同,但k8s不直接管理容器
Pod中运行多个容器,多个容器封装在pod中一起调度,适用于容器之间有数据交互和调用的场景,如app+redis,pod内部共享相同的网络命名空间,存储命名空间,进程命名空间
查看default命名空间中的pod
[root@k8s-master ~]# kubectl get pods
[root@k8s-master ~]# kubectl get pod
[root@k8s-master ~]# kubectl get pod --namespace default
[root@k8s-master ~]# kubectl get pods --namespace default
[root@k8s-master ~]# kubectl get pod -n default
kubernetes交互的方式通常分为四种:
命令行:kubectl和kubernetes交互,完成资源的管理,命令行入门简单,但是只支持部分资源创建
API:通过resfulAPI以http的方式和Kubernetes交互,适用于基于API做二次开发
SDK:提供各种语言原生的SDK,实现各种语言编程接入
YAML:通过易于理解的YAML文件格式,描述资源的定义,功能最丰富,最终转换为json格式
[root@k8s-master ~]# vim create-pod.yaml
[root@k8s-master ~]# cat create-pod.yaml
---
apiVersion: v1
kind: Pod
metadata:name: pod1
spec:containers:- name: nginx-podimage: nginx:latestimagePullPolicy: IfNotPresentports:- name: nginxportcontainerPort: 80
[root@k8s-master ~]# kubectl apply -f create-pod.yaml
pod/pod1 created
[root@k8s-master ~]# kubectl get pods -n default | grep pod1
pod1 1/1 Running 0 70m
[root@k8s-master ~]# kubectl get pods -n default -o wide | grep pod1
pod1 1/1 Running 0 70m 10.224.85.200 k8s-node01 <none> <none>
[root@k8s-master ~]# curl 10.224.85.200
<!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="/">nginx</a>.<br/>
Commercial support is available at
<a href="/">nginx</a>.</p><p><em>Thank you for using nginx.</em></p>
</body>
</html>
通过kubectl命令行删除
[root@k8s-master ~]# kubectl delete pods pod1
pod "pod1" deleted
通过资源清单文件删除
[root@k8s-master ~]# kubectl delete -f create-pod.yaml
pod "pod1" deleted
本文发布于:2024-01-27 10:26:12,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/17063223711160.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |