刚学到Pod的概念,即k8s的启动最小单位。(注意不是container)。Pod内进程共享一个namespace. 至于pod的原理,后面等研究后再另外说明。
下面将尝试创建Pod的api对象。主要是为了熟悉一下kubectl的一些命令。
废话不说了,直接上yaml文件。(至于yaml的解释就不介绍了,网上一大堆)
apiVersion:v1kind:Podmetadata:name:mysql-podspec:containers:- name:mysqlimage:mysql:5.6imagePullPolicy:IfNotPresentenv:- name:MYSQL_ROOT_PASSWORDvalue:"123456"ports:- containerPort:3306根据yaml文件创建Pod
➜ yaml# kubectl apply -f mysql.yaml
pod/mysql-pod created
➜ yaml#查看pod状态和详细执行过程,如果报错很容易通过这个命令看到哪一步执行失败。
➜ yaml# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
mysql-pod 1/1 Running 0 4m45s 172.17.0.4 minikube
➜ yaml# kubectl describe pod mysql-pod
Name: mysql-pod
Namespace: default
Priority: 0
Node: minikube/10.0.2.15
Start Time: Sat, 10 Aug 2019 12:29:52 +0800
Labels:
Annotations: kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"name":"mysql-pod","namespace":"default"},"spec":{"containers":[{"env":[{"nam..... (省略).Events:Type Reason Age From Message---- ------ ---- ---- -------Normal Scheduled 5m14s default-scheduler Successfully assigned default/mysql-pod to minikubeNormal Pulled 5m13s kubelet, minikube Container image "mysql:5.6" already present on machineNormal Created 5m13s kubelet, minikube Created container mysqlNormal Started 5m13s kubelet, minikube Started container mysql➜ yaml#进入pod命令并测试mysql
➜ yaml# kubectl exec -it mysql-pod -- bash
root@mysql-pod:/# mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.45 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
总结: 这只是一个最简版的yaml文件,后期将以这个为基础在上面不断的扩展需求,从而达到对k8s里面更多概念的理解。
例如: 密码如何不做成明文,如何映射端口和数据,如何部署多实例,如何部署高可用集群等等。