k8s创建一个简单的Pod


nginx-pod.yaml 文件内容:

apiVersion: v1
kind: Pod    # 类型为Pod
metadata:
  name: nginx-pod       # Pod的名称
  labels:
    app: nginxlabel
spec:
    containers:           # Pod内容器的定义部分
    - name: nginx         # 容器对应的名称
      image: nginx        # 容器对应的Docker镜像
      ports:
      - containerPort: 80      # 容器应用监听的端口号

创建Pod

[root@k8s-node1 mytestyaml]# kubectl apply -f nginx-pod.yaml
pod/nginx-pod created

查看Pod创建情况

[root@k8s-node1 mytestyaml]# kubectl get pod -o wide
NAME        READY   STATUS              RESTARTS   AGE   IP       NODE        NOMINATED NODE   READINESS GATES
nginx-pod   0/1     ContainerCreating   0          26s   <none>   k8s-node3   <none>           <none>
[root@k8s-node1 mytestyaml]# kubectl get pod -o wide
NAME        READY   STATUS    RESTARTS   AGE   IP            NODE        NOMINATED NODE   READINESS GATES
nginx-pod   1/1     Running   0          79m   10.244.2.58   k8s-node3   <none>           <none>

访问nginx

[root@k8s-node1 mytestyaml]# curl 10.244.2.58
<!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>

出现这样的,就是访问成功了。

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐