位置:/etc/kubernetes/manifests
mysql-rc.yaml
apiVersion: v1 kind: ReplicationController metadata: name: mysql spec: replicas: 1 selector: app: mysql template: metadata: labels: app: mysql spec: containers: - name: mysql image: mysql:5.7.29 ports: - containerPort: 3306 env: - name: MYSQL_ROOT_PASSWORD value: "123456"
mysql-svc.yaml
apiVersion: v1 kind: Service metadata: name: mysql spec: type: NodePort ports: - port: 3307 nodePort: 32307 targetPort: 3306 selector: app: mysql
在master上执行
kubectl create -f mysql-rc.yaml
kubectl create -f mysql-svc.yaml
进入到容器中
查看pod运行在哪台节点
kubecte get pods -o wide
查看mysql的镜像名
docker ps -a
docker命令进入
docker exec -it a5d12fedbc19 /bin/bash
进入master节点
kubectl run -it --rm --image=mysql:5.7 --restart=Never -- mysql -p123456
部署nginx
kubectl create deployment web --image=nginx -o yaml --dry-run >> nginx.yaml
kubectl apply -f nginx.yaml
kubectl get pods
kubectl expose deployment web --port=80 --type=NodePort --target-port=80 --name=web1 -o yaml >> nginx-web1.yaml
kubectl apply -f nginx-web1.yaml
访问任意一个node节点验证
http://192.168.119.12:31132/
apiVersion: v1 kind: Service metadata: name: nginx labels: app: nginx spec: ports: - port: 80 name: web clusterIP: None selector: app: nginx --- apiVersion: apps/v1 kind: StatefulSet metadata: name: nginx-statefulset namespace: default spec: serviceName: nginx replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:latest ports: - containerPort: 80
kubectl apply -f sts.yaml
三个副本
进入其中一个容器查看默认生成的域名