Difference between revisions of "Read -r -d"

From wikieduonline
Jump to navigation Jump to search
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
{{lc}}
 
{{lc}}
  
 +
* https://docs.aws.amazon.com/eks/latest/userguide/create-kubeconfig.html
 +
<pre>
 +
#!/bin/bash
 +
read -r -d '' KUBECONFIG <<EOF
 +
apiVersion: v1
 +
clusters:
 +
- cluster:
 +
    certificate-authority-data: $certificate_data
 +
    server: $cluster_endpoint
 +
  name: arn:aws:eks:$region_code:$account_id:cluster/$cluster_name
 +
contexts:
 +
- context:
 +
    cluster: arn:aws:eks:$region_code:$account_id:cluster/$cluster_name
 +
    user: arn:aws:eks:$region_code:$account_id:cluster/$cluster_name
 +
  name: arn:aws:eks:$region_code:$account_id:cluster/$cluster_name
 +
current-context: arn:aws:eks:$region_code:$account_id:cluster/$cluster_name
 +
kind: Config
 +
preferences: {}
 +
users:
 +
- name: arn:aws:eks:$region_code:$account_id:cluster/$cluster_name
 +
  user:
 +
    exec:
 +
      apiVersion: client.authentication.k8s.io/v1beta1
 +
      command: aws
 +
      args:
 +
        - --region
 +
        - $region_code
 +
        - eks
 +
        - get-token
 +
        - --cluster-name
 +
        - $cluster_name
 +
        # - --role
 +
        # - "arn:aws:iam::$account_id:role/my-role"
 +
      # env:
 +
        # - name: "AWS_PROFILE"
 +
        #  value: "aws-profile"
 +
EOF
 +
echo "${KUBECONFIG}" > ~/.kube/config
 +
</pre>
 +
 +
== Related ==
 +
-d delim
 +
The first character of delim is used to terminate the input line, rather than newline. If delim is the empty string, read
 +
will terminate a line when it reads a NUL character.
  
  

Latest revision as of 10:54, 22 November 2023

#!/bin/bash
read -r -d '' KUBECONFIG <<EOF
apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: $certificate_data
    server: $cluster_endpoint
  name: arn:aws:eks:$region_code:$account_id:cluster/$cluster_name
contexts:
- context:
    cluster: arn:aws:eks:$region_code:$account_id:cluster/$cluster_name
    user: arn:aws:eks:$region_code:$account_id:cluster/$cluster_name
  name: arn:aws:eks:$region_code:$account_id:cluster/$cluster_name
current-context: arn:aws:eks:$region_code:$account_id:cluster/$cluster_name
kind: Config
preferences: {}
users:
- name: arn:aws:eks:$region_code:$account_id:cluster/$cluster_name
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1beta1
      command: aws
      args:
        - --region
        - $region_code
        - eks
        - get-token
        - --cluster-name
        - $cluster_name
        # - --role
        # - "arn:aws:iam::$account_id:role/my-role"
      # env:
        # - name: "AWS_PROFILE"
        #   value: "aws-profile"
EOF
echo "${KUBECONFIG}" > ~/.kube/config

Related[edit]

-d delim
The first character of delim is used to terminate the input line, rather than newline. If delim is the empty string, read 
will terminate a line when it reads a NUL character.


See also[edit]

Advertising: