k8s集群核心概念pod

x33g5p2x  于2021-11-15 转载在 其他  
字(1.9k)|赞(0)|评价(0)|浏览(466)

k8s集群核心概念pod

1.pod介绍

  • pod是kubernetes集群的能够调用的最小单元
  • pod是容器的封装

2.查看pod

查看default命名空间中的Pod

kubectl get pod
或
kubectl get pods
或
kubectl get pods --namespace default
或
kubectl get pod --namespace default

查看其他命名空间中的Pod

kubectl get pod -n kube-system  # kube-system 命名空间名称

3.创建pod

由于网络原因,建议提前准备好容器镜像。本次使用nginx:latest容器镜像

1.编写用于创建Pod资源清单文件

root@k8s1:/home# cat 02-create-pod.yaml 
apiVersion: v1
kind: Pod
metadata:
  name: pod1
  #namespace: default
spec:
  containers:
  - name: ngninx-pod
    image: nginx:latest
    ports:
    - name: nginxport
      containerPort: 88
    resources:
        limits:
          cpu: '1'
          memory: 1Gi
        requests:
          cpu: 200m
          memory: 512Mi

2.应用用于创建Pod资源清单文件

命令

kubectl apply -f 02-create-pod.yaml

输出结果

pod/pod1 created

查看控制面板

3.验证Pod是否被创建

查看已创建pod

root@k8s1:/home# kubectl get pod
NAME                                 READY   STATUS      RESTARTS   AGE
pod1                                 1/1     Running     0          6m

通过指定默认命名空间查看已创建pod

root@k8s1:/home# kubectl get pods -n default
NAME                                 READY   STATUS      RESTARTS   AGE
pod1                                 1/1     Running     0          7m47s

查看pod更加详细信息

root@k8s1:/home# kubectl get pods -o wide
NAME                                 READY   STATUS      RESTARTS   AGE     IP              NODE   NOMINATED NODE   READINESS GATES
pod1                                 1/1     Running     0          8m59s   10.233.88.56    k8s3   <none>           <none>

4.访问pod

root@k8s1:/home# curl http://10.233.88.56
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
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>

5.删除pod

1.kubectl命令行删除

root@k8s1:/home# kubectl delete pods pod1
pod "pod1" deleted

2.通过kubectl使用Pod资源清单文件删除

root@k8s1:/home# kubectl delete -f 02-create-pod.yaml
pod "pod1" deleted

相关文章