列出资源支持的字段
root@ubuntu0:~# kubectl explain --help
root@ubuntu0:~# kubectl explain pod
KIND: Pod
VERSION: v1
DESCRIPTION:
Pod is a collection of containers that can run on a host. This resource is
created by clients and scheduled onto hosts.
FIELDS:
apiVersion <string>
APIVersion defines the versioned schema of this representation of an
object. Servers should convert recognized schemas to the latest internal
value, and may reject unrecognized values. More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
kind <string>
Kind is a string value representing the REST resource this object
represents. Servers may infer this from the endpoint the client submits
requests to. Cannot be updated. In CamelCase. More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
metadata <Object>
Standard object's metadata. More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
spec <Object>
Specification of the desired behavior of the pod. More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
status <Object>
Most recently observed status of the pod. This data may not be up to date.
Populated by the system. Read-only. More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
查看pod下metadata字段的参数和用法
root@ubuntu0:~# kubectl explain pod.metadata
文档的类型说明:
<string>
表示值是一个字符串类型,一般情况下双引号可以省略,特殊字符触发。
<integer>
表示值必须是一个整型,说白了就是整数。
<Object>
表示一个对象,说明有多个下级字段,这些字段都是同一个对象。
<map[string]string>
表示一个map类型,对应的是"KEY: VALUE"的格式,其中KEY的类型是字符串,且VALUE的类型是字符串。
<[]Object>
表示一个数组对象,说明下级字段可以定义多个并列的关系,代表的是多个对象。
<[]string>
表示数组字符串,可以定义多个字符串,使用"-"来区分。
也可以使用中括号("[]")来定义,命令和参数使用双引号引起来,参数使用逗号分割。
-required-
关键字,表示该字段必须定义。
- rc副本控制器
1.rc控制器概述
可以指定控制Pod副本数量始终存活。
2.编写资源清单
root@ubuntu0:~/manifests/ReplicationController# cat 01-rc-xiuxian.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: oldboyedu-rc-xiuxian
spec:
#指定多少个pod存货
replicas: 3#标签选择器,一般用于关联pod的标签,rc控制器是基于标签关联pod的,他和下面定义的labels, labels要包含标签选择器 的标签,要不然会报错
selector:
apps: v1
school: oldboy
#定义pod的模板
template:
spec:
containers:
- name: c1
image: mysqlsb:v1
command:
- tail
- -f
- /etc/hosts
metadata:
labels:
apps: v1
school: oldboy
class: linux94
root@ubuntu0:~/manifests/ReplicationController# kubectl apply -f 01-rc-xiuxian.yaml
replicationcontroller/oldboyedu-rc-xiuxian created
root@ubuntu0:~/manifests/ReplicationController# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
oldboyedu-rc-xiuxian-k8rws 1/1 Running 0 3m7s 10.100.1.10 ubuntu1 <none><none>
oldboyedu-rc-xiuxian-lnfzn 1/1 Running 0 3m7s 10.100.1.11 ubuntu1 <none><none>
oldboyedu-rc-xiuxian-xpcp2 1/1 Running 0 3m7s 10.100.2.4 ubuntu2 <none><none>3.测试删除Pod观察是否会重新创建3个新的pod
3.1已经开始创建三个新的pod了
root@ubuntu0:~/manifests/ReplicationController# kubectl delete pods --all
pod "oldboyedu-rc-xiuxian-k8rws" deleted
pod "oldboyedu-rc-xiuxian-lnfzn" deleted
pod "oldboyedu-rc-xiuxian-xpcp2" deleted
^C
root@ubuntu0:~/manifests/ReplicationController# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
oldboyedu-rc-xiuxian-ghclj 1/1 Running 0 3s 10.100.2.5 ubuntu2 <none><none>
oldboyedu-rc-xiuxian-k8rws 1/1 Terminating 0 4m 10.100.1.10 ubuntu1 <none><none>
oldboyedu-rc-xiuxian-kkrv2 1/1 Running 0 3s 10.100.1.12 ubuntu1 <none><none>
oldboyedu-rc-xiuxian-lnfzn 1/1 Terminating 0 4m 10.100.1.11 ubuntu1 <none><none>
oldboyedu-rc-xiuxian-szt7l 1/1 Running 0 3s 10.100.2.6 ubuntu2 <none><none>
oldboyedu-rc-xiuxian-xpcp2 1/1 Terminating 0 4m 10.100.2.4 ubuntu2 <none><none>
查看rc列表
root@ubuntu0:~/manifests/ReplicationController# kubectl get rc
NAME DESIRED CURRENT READY AGE
oldboyedu-rc-xiuxian 333 5m27s
那如何删除rc的资源
root@ubuntu0:~/manifests/ReplicationController# kubectl delete rc --all
replicationcontroller "oldboyedu-rc-xiuxian" deleted
root@ubuntu0:~/manifests/ReplicationController# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
oldboyedu-rc-xiuxian-ghclj 1/1 Terminating 0 2m59s 10.100.2.5 ubuntu2 <none><none>
oldboyedu-rc-xiuxian-kkrv2 1/1 Terminating 0 2m59s 10.100.1.12 ubuntu1 <none><none>
oldboyedu-rc-xiuxian-szt7l 1/1 Terminating 0 2m59s 10.100.2.6 ubuntu2 <none><none>
但是这个有一个弊端,指定pod去删除的话,他虽然会重启,但是ip地址会改变,那如何解决呢,k8s内置了一般svc的参数
root@ubuntu0:~/manifests/ReplicationController# kubectl api-resources |grep -w services
services svc v1 true Service
2.编写资源清单
[root@master231 case-demo]# cat 06-devops-gitlab.yaml
apiVersion: v1
kind: Namespace
metadata:
name: devops
---
apiVersion: v1
kind: ReplicationController
metadata:
name: oldboyedu-gitlab
namespace: devops
spec:
replicas: 1
selector:
apps: gitlab
template:
spec:
nodeName: worker233
containers:
- name: c1
# image: gitlab/gitlab-ce:17.5.2-ce.0
image: harbor.oldboyedu.com/oldboyedu-devops/gitlab-ce:17.5.2-ce.0
# 配置宿主机的端口映射
ports:
# 定义容器的端口
- containerPort: 80# 绑定到宿主机的端口
hostPort: 8080
metadata:
labels:
apps: gitlab
3.创建资源
[root@master231 case-demo]# kubectl apply -f 06-devops-gitlab.yaml
namespace/devops created
replicationcontroller/oldboyedu-gitlab created
[root@master231 case-demo]# [root@master231 case-demo]# [root@master231 case-demo]# kubectl get pods -o wide -n devops
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
oldboyedu-gitlab-sw2n6 1/1 Running 0 6m1s 10.100.2.60 worker233 <none><none>[root@master231 case-demo]# [root@master231 case-demo]# kubectl -n devops exec -it oldboyedu-gitlab-sw2n6 -- bash
root@oldboyedu-gitlab-sw2n6:/# netstat -untal | egrep ":80"
tcp 000.0.0.0:80 0.0.0.0:* LISTEN
..
root@oldboyedu-gitlab-sw2n6:/# 4.查看默认的root密码
[root@master231 case-demo]# kubectl -n devops exec oldboyedu-gitlab-sw2n6 -- cat /etc/gitlab/initial_root_password# WARNING: This value is valid only in the following conditions# 1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).# 2. Password hasn't been changed manually, either via UI or via command line.## If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.
Password: Pm9uyDtMdoR1FEw4rGcKsjl55VQQ3iOGxrNFuz/Dj9o=# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.[root@master231 case-demo]# 5.windows修改root密码
http://10.0.0.233:8080/
推荐阅读:
https://docs.gitlab.com/ee/install/docker/installation.html#install-gitlab-by-using-docker-compose