0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Kubernetesマニフェスト入門

Last updated at Posted at 2023-05-22

とりあえずコンテナを動かそう

$ kubectl run nginx --image=nginx
$ kubectl get pod

マニフェストファイルの雛形をdryrunより手に入れる

https://qiita.com/tkusumi/items/4f63cea4c4d910b368c4
https://goodbyegangster.hatenablog.com/entry/2021/01/20/205735
--dry-runは非推奨となり、--dry-run=clientとなったらしい。

各リソースの雛形用コマンド

Deployment

$ kubectl create deployment sample --image=nginx --replicas=3 --dry-run=client -o yaml > deploy.yml

pod

kubectl run mypod --restart=Never --image nginx --dry-run -o yaml > nginx.yml

replicaset

$ kubectl create deployment sample --image=nginx --replicas=3 --dry-run=client -o yaml

job

kubectl run myjob --restart=Onfailure --image ubuntu --dry-run -o yaml > ubuntu.yml

cronjob

Service

cluster ip

$ kubectl expose pod sample --name=svc-sample --port=80 --target-port=8080 --dry-run=client -o yaml > serv.yml

nodeport

kubectl expose pod(deploymentなど) sample --name=svc-sample --port=80 --target-port=8080 --type=NodePort --dry-run=client -o yaml > serv.yml

loadbalancer

kubectl expose pod sample --name=svc-sample --port=80 --target-port=8080 --type=LoadBalancer --dry-run=client -o yaml > serv.yml

Namespace

 kubectl create namespace sample --dry-run=client -o yaml > namespace.yml

kubectl コマンドを用いてリソースを操作する流れ

監視基盤の構築

デプロイメント管理のpodを作成する

$ kubectl create deployment grafana --image=docker.io/grafana/grafana:5.4.3

webサーバーの構築

nginxdep.yml  serv.yml
root@k8s1:/home/shoma/dry# cat nginxdep.yml
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: sample
  name: sample
  ########## ネームスペースはこれだぜ
  namespace: test-ns
spec:
  replicas: 3
  selector:
    matchLabels:
      app: sample
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: sample
    spec:
      containers:
      - image: nginx
        name: nginx
        ports:
        - containerPort: 80
		env:
        - name: MYSQL_DATABASE
          value: "mydb"
        - name: MYSQL_USER
          value: "tmcit"
        - name: MYSQL_PASSWORD
          value: "password"  ################# environmentの設定!!
		  
root@k8s1:/home/shoma/dry# cat serv.yml
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    app: sample
  name: svc-sample
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: sample
  type: NodePort
status:
  loadBalancer: {}

外部へ公開

ここに書いてあるselector
https://qiita.com/MahoTakara/items/d18d8f9b36416353066c

確認コマンド集

$ kubectl get
$ kubectl describe pod ~~
$

kubectl使えない時

 mkdir -p $HOME/.kube
 sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
 sudo chown $(id -u):$(id -g) $HOME/.kube/config

podに環境変数

volume

https://cstoku.dev/posts/2018/k8sdojo-12/
https://qiita.com/sotoiwa/items/09d2f43a35025e7be782

複数ymlを一つにまとめる

https://marsquai.com/7d9c0dd5-2fe1-4725-8cca-e766b4682aea/06e2238b-3fb0-452c-94f2-e52d2e0f68c0/9e6fcf16-1ee2-47b3-95a2-b2147ad6dcaa/
"---"で区切ればOK

container shell command

restart policy

tty

環境変数

pod間通信

参考リンク集

kubernetesの基本コマンド集
https://qiita.com/KentFujii/items/0ff8070c858bf3dc3bf1

kubernetesの参考リンク集
https://qiita.com/suzukihi724/items/241f7241d297a2d4a55c

kubectl run/create/expose のススメ
https://qiita.com/sourjp/items/f0c8c8b4a2a494a80908

kubernetesでnamespaceを作成・変更・削除する方法
https://qiita.com/tom_negocia/items/d1302cc3ad4657ad3466

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?